https://www.cs.toronto.edu/~arnold/427/19s/427_19S/tool/ssl/notes.pdf

CHANGE OWNER

OPENSSL - Open Secure Socket Layer

Asymmetric Encryption

Encryption mit einem Public und einem Private key : ==Confidentiality==

→ Signing ! mittels des eigenen Private Key : ==Authenticity==, Eve cannot defraud Alice


Encryption - What not to do

openssl aes-128-cbc -e </etc/passwd >passwd.encrypted openssl aes-128-cbc -d <passwd.encrypted >passwd.plaintext

==do not use ECB–Mode → Penguin Still intact, just different colors==

Instead : CBC Mode - Cipher Block Chaining

Warum das sicherer ist als ECB

  • In ECB (Electronic Codebook) werden gleiche Plaintext-Blöcke gleich verschlüsselt → Muster sichtbar (wie beim bunten Pinguin).

  • In CBC hängt jeder Block vom vorherigen ab → auch wenn sich ein Plaintext-Block wiederholt, ist der Ciphertext anders.


Linking a Person to a String

UNIX Design

In Unix, everything is a file, meaning it has a file interface

  • plain Files

  • directories

  • devices

  • main memmory

  • users are contained in groups

  • Files are owned by a user and a group

  • there is one super user

Processes in UNIX

Programs and Processes

  • A program is an executable file. It can be:

    • A compiled program (from non–executable source, e.g., C, C++)

    • An interpreted program (e.g., Java, Shell, Perl, …)

      • Note: Shell, Java, and Perl interpreters themselves are compiled programs.

  • ==A process is a program currently executed by a processor.==

  • A process uses:

    • Code of the programmer

    • The C library

    • The operating system

  • Process return values (byte values):

    • 0 → success (true)

    • > 0 and ≤ 255 → failure (false)

  • Ownership:

    • Processes are owned by the user who started them.
  • Capabilities:

    • Processes can manipulate Files.

    • The process table can be viewed using:

      	ps

      (process status)

Process : Layer Modell

Wir nutzen ein Layer modell um Programme Strukturieren zu können, nicht alles neu erfinden zu müssen und um Bugs effizienter finden zu können.

  1. User Interface (Shell / Gui)

    • Hier interagiert der User mit dem Programm
  2. Application Programme

    • Hier läuft das eigentliche Anwendungsprogramm (z. B. Texteditor, Webbrowser).
  3. Library ( OS / Applikation )

    • Sammulung von Funktionen die oft gebraucht werden

    • Erspart dem Programm alles neu zu erfinden

  4. System Calls (OS)

    • Schnittstelle zum OS-Kernel

    • Befehle wie open( ), read ( ), write ( ), fork ( ) werden hier aufgerufen

Kommunikation :

Programms calling Libraries

Application Programme ↔ Library ( OS / Applikation )

  • functions are called

  • termination : return value

Starting other Processes

User Interface (Shell / Gui) ↔ Application Programme

  • processes are created by the OS

  • termination : exit value needed

Programs/Libraries Calling System Interface

Application Programme ↔ Library ( OS / Applikation ) ↔ Systems Calls (OS)

  • system call functions are called

  • termination : return value

  • return value must be checked for < 0

Errors on System Calls

  • Gobal variable errno is defined

  • perror( ) : print String for error

  • strerror( ) Create a String for the specific error

Linking of Library Functions

Static Linking :

  • All Library Functions are incorporated into the Programme at runtime

  • Saves a lot of Function calls

  • Errors in Libraries only ion corresponding programms

  • Changes in Library might require Recompiling

Dynamic Linking :

  • Library Functions load on demand into the programme at Runtime

  • Saves RAM, as Functions loaded on demand

  • Simplifies Security Patches

  • Compability with Library has to be ensured

Dependecy Hell

Entsteht, wenn viele Programme voneinander Abhängige Bibliotheken nutzen

  • Versionskonflikte : Verschiedene Programme Brauchen verschiedene Versionen von Dependencies

  • BugFixes oder Änderungen kann transitive Folgen haben

Important

Solution : Package Manager, der Dependencies automatisch auflöst.

C Code

\#include <stdio.h>
 
int main(int argc, char **argv){
 
		FILE *f;
		
		if (argc<=1) return 1;
		f=fopen(argv[1],"w");
		if (!f) return 1;
		fprintf(f,"hello world\n");
		
		fclose(f);
return 0;
 
}

f=fopen(argv[1],"w");

  • Open im Write Modus, falls existiert, dann überschreiben, sonst neu erstellen

Important

ldd liest aus einem C Programm alle dynamisch hinzugefügten Bibliotheken heraus, listet diese auf.

System Calls

ktrace

  • Strtet ein Programm und zeichnet alle System Calls auf, die dieses Programm macht.

  • Ein==Systemaufruf== (z. B. open, write, read, close) ist der Weg, wie ein Programm mit dem Kernel interagiert.

kdump

Da ktrace alles in Binary ausgibt, ist es nicht für Menschen lesbar.

kdump wandelt diese Ausgabe in Natürliche Sprache um !

  • man bekommt eine Liste:

    • Welcher Systemaufruf wurde gemacht (CALL)

    • Mit welchen Parametern

    • Was zurückkam (RET) — inklusive Fehlercodes

Important System Calls

------------------------------------------------------
Files Creating a Channel creat()
open()
close()
Input/Output read()
write()
Random Access lseek()
Channel Duplication dup()
Aliasing and Removing link()
Files unlink()
File Status stat()
Access Control access()
chmod()
chown()
umask()
Device Control ioctl()
-----------------------------------------------------------
Processes Process Creation exec()
fork()
Termination wait()
exit()
Process Owner and Group getuid()
geteuid()
getgid()
getegid()
Process Identity getpid()
getppid()
Process Control signal()
kill()
alarm()
Change Working Directory chdir()
----------------------------------------------------------
IPC Pipelines pipe()
Messages msgget()
msgsnd()
msgrcv()
msgctl()
Semaphores semget()
semop()
Shared Memory shmget()
shmat()
shmdt()
-------------------------------------------------------

System Calls im C Code Beispiel :

\#include <sys/types.h>
\#include <sys/stat.h>
\#include <fcntl.h>
\#include <unistd.h>
\#include <stdio.h>
 
int main(int argc, char **argv)
{
    int fd; /* file descriptor */
 
    if (argc <= 1)
        return 1;
 
    fd = open(argv[1], O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
    if (fd < 0) {
        perror("open");
        return 1;
    }
 
    if (write(fd, "hello world\n", 12) < 0) {
        perror("write()");
        return 1;
    }
 
    if (close(fd) < 0) {
        perror("close()");
        return 1;
    }
 
    return 0;
}

fd → File Descriptor, Wert von dem OS für eine geöffnete Datei

  • 0 = Standard Input

  • 1 = Standard Output

  • 2 = Standard Error

  • >=3 = normale Dateien/Sockets etc.

Important

fd = open(argv[1], O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);

  • Öffnet die Datei schreibend (O_WRONLY)

  • Falls nicht vorhanden, wird sie erstellt (O_CREAT)

  • Rechte:

    • S_IRUSR = Lese-Recht für den Besitzer

    • S_IWUSR = Schreib-Recht für den Besitzer

  • Rückgabewert:

    • ≥0 → Erfolg (Dateideskriptor)

    • <0 → Fehler