Compare commits
No commits in common. 'main' and 'devel_freefall' have entirely different histories.
main
...
devel_free
@ -1,135 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> |
||||
<ItemGroup Label="ProjectConfigurations"> |
||||
<ProjectConfiguration Include="Debug|Win32"> |
||||
<Configuration>Debug</Configuration> |
||||
<Platform>Win32</Platform> |
||||
</ProjectConfiguration> |
||||
<ProjectConfiguration Include="Release|Win32"> |
||||
<Configuration>Release</Configuration> |
||||
<Platform>Win32</Platform> |
||||
</ProjectConfiguration> |
||||
<ProjectConfiguration Include="Debug|x64"> |
||||
<Configuration>Debug</Configuration> |
||||
<Platform>x64</Platform> |
||||
</ProjectConfiguration> |
||||
<ProjectConfiguration Include="Release|x64"> |
||||
<Configuration>Release</Configuration> |
||||
<Platform>x64</Platform> |
||||
</ProjectConfiguration> |
||||
</ItemGroup> |
||||
<ItemGroup> |
||||
<ClCompile Include="main.c" /> |
||||
</ItemGroup> |
||||
<PropertyGroup Label="Globals"> |
||||
<VCProjectVersion>16.0</VCProjectVersion> |
||||
<Keyword>Win32Proj</Keyword> |
||||
<ProjectGuid>{4f23ba48-5e70-4fbb-a131-26176c695776}</ProjectGuid> |
||||
<RootNamespace>SW05SHA1</RootNamespace> |
||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion> |
||||
</PropertyGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>true</UseDebugLibraries> |
||||
<PlatformToolset>v143</PlatformToolset> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>false</UseDebugLibraries> |
||||
<PlatformToolset>v143</PlatformToolset> |
||||
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>true</UseDebugLibraries> |
||||
<PlatformToolset>v143</PlatformToolset> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> |
||||
<ConfigurationType>Application</ConfigurationType> |
||||
<UseDebugLibraries>false</UseDebugLibraries> |
||||
<PlatformToolset>v143</PlatformToolset> |
||||
<WholeProgramOptimization>true</WholeProgramOptimization> |
||||
<CharacterSet>Unicode</CharacterSet> |
||||
</PropertyGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> |
||||
<ImportGroup Label="ExtensionSettings"> |
||||
</ImportGroup> |
||||
<ImportGroup Label="Shared"> |
||||
</ImportGroup> |
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
</ImportGroup> |
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
</ImportGroup> |
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
</ImportGroup> |
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> |
||||
</ImportGroup> |
||||
<PropertyGroup Label="UserMacros" /> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<SDLCheck>true</SDLCheck> |
||||
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<ConformanceMode>true</ConformanceMode> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<ConformanceMode>true</ConformanceMode> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
<OptimizeReferences>true</OptimizeReferences> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<SDLCheck>true</SDLCheck> |
||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<ConformanceMode>true</ConformanceMode> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> |
||||
<ClCompile> |
||||
<WarningLevel>Level3</WarningLevel> |
||||
<FunctionLevelLinking>true</FunctionLevelLinking> |
||||
<IntrinsicFunctions>true</IntrinsicFunctions> |
||||
<SDLCheck>true</SDLCheck> |
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions> |
||||
<ConformanceMode>true</ConformanceMode> |
||||
</ClCompile> |
||||
<Link> |
||||
<SubSystem>Console</SubSystem> |
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding> |
||||
<OptimizeReferences>true</OptimizeReferences> |
||||
<GenerateDebugInformation>true</GenerateDebugInformation> |
||||
</Link> |
||||
</ItemDefinitionGroup> |
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> |
||||
<ImportGroup Label="ExtensionTargets"> |
||||
</ImportGroup> |
||||
</Project> |
||||
@ -1,216 +0,0 @@ |
||||
/**
|
||||
*--------------------------------------------------------------------\n |
||||
* HSLU T&A Hochschule Luzern Technik+Architektur \n |
||||
*--------------------------------------------------------------------\n |
||||
* |
||||
* \brief ASYD assignment crypto 05 |
||||
* \file |
||||
* \author Basil Estermann, basil.estermann@stud.hslu.ch |
||||
* Simon Frei, simon.frei@stud.hslu.ch |
||||
* Jonas Arnold, jonas.arnold@stud.hslu.ch |
||||
* \date 23.03.2023 |
||||
* |
||||
*-------------------------------------------------------------------- |
||||
*/ |
||||
|
||||
#include <stdint.h> |
||||
#include <stdlib.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
#include <stdint.h> |
||||
|
||||
#define VALUE_LENGTH 32 |
||||
#define MESSAGE_DIGEST_LENGTH 160 |
||||
#define BLOCK_LENGTH (512/8) |
||||
#define INPUT_MESSAGE ("Lorem ipsum dolor sit amet, consetetur sadipscing.") |
||||
|
||||
#pragma region Macros |
||||
#define INT_64_LOW_BYTE(input) (input & 0xff) |
||||
#define INT_64_HIGH_BYTE(input) ((input>>8) & 0xff) |
||||
#pragma endregion |
||||
|
||||
#pragma region SHA1-Constants |
||||
// initial hash values
|
||||
#define H0 0x67452301 |
||||
#define H1 0xEFCDAB89 |
||||
#define H2 0x98BADCFE |
||||
#define H3 0x10325476 |
||||
#define H4 0xC3D2E1F0 |
||||
// constants Kt
|
||||
#define K1 0x5A827999 |
||||
#define K2 0x6ED9EBA1 |
||||
#define K3 0x8F1BBCDC |
||||
#define K4 0xCA62C1D6 |
||||
#pragma endregion |
||||
|
||||
void printBits(size_t const size, void const* const ptr); |
||||
uint32_t leftRotate(uint32_t n, uint32_t d); |
||||
uint32_t SHA1_f1(uint32_t b, uint32_t c, uint32_t d); |
||||
uint32_t SHA1_f2(uint32_t b, uint32_t c, uint32_t d); |
||||
uint32_t SHA1_f3(uint32_t b, uint32_t c, uint32_t d); |
||||
uint32_t SHA1_f4(uint32_t b, uint32_t c, uint32_t d); |
||||
|
||||
void main(void) { |
||||
|
||||
int result = 0; |
||||
|
||||
printf("****** SHA1 preprocessing ******\n\n"); |
||||
#pragma region Preprocessing |
||||
|
||||
printf("------ Set initial hash value ------\n\n"); |
||||
#pragma region Initial Hash values |
||||
uint32_t a, b, c, d, e; |
||||
uint32_t h[5] = { H0, H1, H2, H3, H4 }; |
||||
uint32_t k[5] = { 0, K1, K2, K3, K4 }; // 5 so the array can be accessed by 1, 2, 3, 4
|
||||
a = h[0]; |
||||
b = h[1]; |
||||
c = h[2]; |
||||
d = h[3]; |
||||
e = h[4]; |
||||
|
||||
#pragma endregion |
||||
|
||||
if (sizeof(INPUT_MESSAGE) * 8 > 447) { |
||||
printf("Message too long!"); |
||||
return 1000002; |
||||
} |
||||
|
||||
printf("------ Padding message ------\n\n"); |
||||
#pragma region Padding |
||||
// print information about message without padding
|
||||
unsigned char messageNoPadding[] = INPUT_MESSAGE; |
||||
int numBytesMessage = (sizeof(INPUT_MESSAGE) - 1); // -1 because of '\0' at end of the string
|
||||
printf("Size of message without padding: %i bits\n", numBytesMessage*8); |
||||
printf("Message without padding\n"); |
||||
printBits(sizeof(messageNoPadding), &messageNoPadding); |
||||
|
||||
unsigned char message[BLOCK_LENGTH] = ""; |
||||
// fill in message
|
||||
for (uint32_t i = 0; i < numBytesMessage; i++) |
||||
{ |
||||
message[i] = INPUT_MESSAGE[i]; |
||||
} |
||||
// set bit
|
||||
message[numBytesMessage] = 0b10000000; |
||||
printf("\nMessage after adding 1: \n"); |
||||
printBits(sizeof(message), &message); |
||||
// add length with high and low byte (length is 64bit)
|
||||
message[BLOCK_LENGTH - 1] = INT_64_LOW_BYTE(numBytesMessage * 8); |
||||
message[BLOCK_LENGTH - 2] = INT_64_HIGH_BYTE(numBytesMessage * 8); |
||||
printf("\nMessage after adding length: \n"); |
||||
printBits(sizeof(message), &message); |
||||
#pragma endregion |
||||
|
||||
#pragma endregion |
||||
|
||||
printf("\n\n****** Hash computation ******\n\n"); |
||||
#pragma region Hash computation |
||||
|
||||
printf("\n------ Prepare message schedule ------\n\n"); |
||||
#pragma region Prepare message schedule |
||||
uint32_t WordArray[80] = { 0 }; |
||||
for (uint32_t i = 0; i < 16; i++) { |
||||
uint32_t currentbyte = message[i] << 24; |
||||
uint32_t tmp = (uint32_t)(((uint8_t)(message[i * 4]) << 24) + ((uint8_t)(message[4 * i + 1]) << 16) + ((uint8_t)(message[4 * i + 2]) << 8) + (uint8_t)(message[4 * i + 3])); |
||||
WordArray[i] = tmp; |
||||
} |
||||
for (uint32_t i = 16; i < 80; i++) { |
||||
WordArray[i] = leftRotate((WordArray[i - 3] ^ WordArray[i - 8] ^ WordArray[i - 14] ^ WordArray[i - 16]), 1); |
||||
} |
||||
#pragma endregion |
||||
|
||||
printf("\n------ Stages ------\n\n"); |
||||
#pragma region Stages calculations |
||||
uint32_t (*f_ptr)(uint32_t, uint32_t, uint32_t) = &SHA1_f1; // use: (*f_ptr)(b,c,d);
|
||||
uint8_t stage = 1; |
||||
// print header row
|
||||
printf("\tA\t\tB\t\tC\t\tD\t\tE\n"); |
||||
|
||||
// stage 1...4
|
||||
for (uint32_t t = 0; t < 80; t++) { |
||||
uint32_t T = leftRotate(a, 5) + ((*f_ptr)(b, c, d)) + e + k[stage] + WordArray[t]; |
||||
e = d; |
||||
d = c; |
||||
c = leftRotate(b, 30); |
||||
b = a; |
||||
a = T; |
||||
|
||||
// print row
|
||||
printf("t= %02d:\t%08X\t%08X\t%08X\t%08X\t%08X\t\n", t, a, b, c, d, e); |
||||
|
||||
// switch stages
|
||||
if (t == 19) { f_ptr = SHA1_f2; stage = 2; printf("Switched to stage 2.\n"); } |
||||
else if (t == 39) { f_ptr = SHA1_f3; stage = 3; printf("Switched to stage 3.\n"); } |
||||
else if (t == 59) { f_ptr = SHA1_f4; stage = 4; printf("Switched to stage 4.\n"); } |
||||
} |
||||
#pragma endregion |
||||
|
||||
printf("\n------ Intermediate hash calculation ------\n\n"); |
||||
#pragma region intermediate hash calculation |
||||
uint32_t summand[5] = { a, b, c, d, e }; |
||||
for (uint8_t i = 0; i < 5; i++) { |
||||
// calculate
|
||||
uint32_t h_new = summand[i] + h[i]; |
||||
// print
|
||||
printf("H[%i] = %08X + %08X = %08X\n", i, summand[i], h[i], h_new); |
||||
// set value
|
||||
h[i] = h_new; |
||||
} |
||||
|
||||
#pragma endregion |
||||
#pragma endregion |
||||
|
||||
printf("\n****** Resulting hash ******\n\n"); |
||||
for (uint8_t i = 0; i < 5; i++) { |
||||
printf("%X ", h[i]); |
||||
} |
||||
printf("\n\n"); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
uint32_t SHA1_f1(uint32_t b, uint32_t c, uint32_t d) { |
||||
return (b & c) | (~b & d); |
||||
} |
||||
|
||||
uint32_t SHA1_f2(uint32_t b, uint32_t c, uint32_t d) { |
||||
return b ^ c ^ d; |
||||
} |
||||
|
||||
uint32_t SHA1_f3(uint32_t b, uint32_t c, uint32_t d) { |
||||
return (b & c) | (b & d) | (c & d); |
||||
} |
||||
|
||||
uint32_t SHA1_f4(uint32_t b, uint32_t c, uint32_t d) { |
||||
return b ^ c ^ d; |
||||
} |
||||
|
||||
uint32_t leftRotate(uint32_t n, uint32_t d) |
||||
{ |
||||
/* In n<<d, last d bits are 0. To put first 3 bits of n at
|
||||
last, do bitwise or of n<<d with n >>(INT_BITS - d) */ |
||||
return (n << d) | (n >> (VALUE_LENGTH - d)); |
||||
} |
||||
|
||||
// Assumes little endian
|
||||
void printBits(size_t const size, void const* const ptr) |
||||
{ |
||||
unsigned char* b = (unsigned char*)ptr; |
||||
unsigned char byte; |
||||
int i, j; |
||||
|
||||
for (i = 0; i < size; i++) { |
||||
for (j = 7; j >= 0; j--) { |
||||
byte = (b[i] >> j) & 1; |
||||
printf("%u", byte); |
||||
} |
||||
} |
||||
/*original:
|
||||
for (i = size - 1; i >= 0; i--) { |
||||
for (j = 7; j >= 0; j--) { |
||||
byte = (b[i] >> j) & 1; |
||||
printf("%u", byte); |
||||
} |
||||
}*/ |
||||
puts(""); |
||||
} |
||||
@ -1,11 +0,0 @@ |
||||
Assignment crypto 05 |
||||
Gruppenmitglieder: Basil Estermann, Jonas Arnold, Simon Frei |
||||
|
||||
Wir konnten erfolgreich einen SHA-1 Hash Generator implementieren. Wie vorgesehen lässt sich der SHA-1 mit den verhältnismässig kleinen Zahlen (32bit) gut implementieren, auch beispielsweise auf Embedded Systemen mit der Programmiersprache C. |
||||
Bei der Implementierung haben wir uns hauptsächlich auf das Dokument der NIST gestützt. Das Preprocessing bzw. Padding der Nachricht haben wir gemäss Abschnitt 5.1.1. implementiert. Aktuell kann unser Programm nur den Hash von eine Nachricht (1 Block a 512bit, mit Padding also maxima 447bit für Nachricht bzw. 55 ASCII Zeichen) berechnen. Dies wäre einfach erweiterbar gemäss Abschnitt 5.2.1. Die Hash Berechnung, welche wir anhand Abschnitt 6.1.2 implementiert haben, müsste ebenfalls um eine for-schleife von "i=1 bis N" erweitert werden. |
||||
|
||||
Verifiziert haben wir unseren Generator einerseits mit den hilfreichen SHA1_DebugHelp.pdf von ILIAS. Damit war einfach nachvollziehbar wo unser Programm falsch rechnet. Ausserdem haben wir einen online SHA-1 Generator (http://www.sha1-online.com/) verwendet, um weitere Nachrichten zu testen. |
||||
Mithilfe dieser Verifikation war es möglich den Algorithmus zum Laufen zu bringen. Ein Prolglem bei der Implementierung war, dass wir erst den String-Ende Indikator ('\0') auch in den Hash integriert hatten, was dann zu anderen Hashes geführt hat als z.B. dem online SHA-1 Generator. Dieses Problem konnte jedoch rasch behoben werden, indem das '\0' einfach nicht miteinbezogen wird. |
||||
|
||||
Beim Testen vom Hash einer Gruppen auf Ilias mussten wir jedoch feststellen, dass unser SHA-1 Generator nur bis zu einer Nachrichtengrösse von 32 Zeichen funktioniert. Der Grund dafür war, dass wir lediglich das Low-Byte der Länge der Nachricht in das Padding der Nachricht integriert hatten. Nachdem wir auch das High-Byte integrierten (nun also volle 64bit für die Länge der Nachricht am Ende des Message Blocks) konnten wir den SHA-1 Hash der anderen Gruppe OdermattStefan/PfrennigerDavid auch erfolgreich generieren. |
||||
Leider war zum Zeitpunkt dieses Berichts auch nur ein einziges Testfile einer anderen Gruppe im Austausch-Ordner. |
||||
@ -1,4 +0,0 @@ |
||||
Message: |
||||
Lorem ipsum dolor sit amet, consetetur sadipscing. |
||||
Hash: |
||||
95A2B0D2 1278E3CB EF1D6F24 59366764 D0648AA7 |
||||
@ -1,216 +0,0 @@ |
||||
/**
|
||||
*--------------------------------------------------------------------\n |
||||
* HSLU T&A Hochschule Luzern Technik+Architektur \n |
||||
*--------------------------------------------------------------------\n |
||||
* |
||||
* \brief ASYD assignment crypto 05 |
||||
* \file |
||||
* \author Basil Estermann, basil.estermann@stud.hslu.ch |
||||
* Simon Frei, simon.frei@stud.hslu.ch |
||||
* Jonas Arnold, jonas.arnold@stud.hslu.ch |
||||
* \date 23.03.2023 |
||||
* |
||||
*-------------------------------------------------------------------- |
||||
*/ |
||||
|
||||
#include <stdint.h> |
||||
#include <stdlib.h> |
||||
#include <stdio.h> |
||||
#include <string.h> |
||||
#include <stdint.h> |
||||
|
||||
#define VALUE_LENGTH 32 |
||||
#define MESSAGE_DIGEST_LENGTH 160 |
||||
#define BLOCK_LENGTH (512/8) |
||||
#define INPUT_MESSAGE ("Lorem ipsum dolor sit amet, consetetur sadipscing.") |
||||
|
||||
#pragma region Macros |
||||
#define INT_64_LOW_BYTE(input) (input & 0xff) |
||||
#define INT_64_HIGH_BYTE(input) ((input>>8) & 0xff) |
||||
#pragma endregion |
||||
|
||||
#pragma region SHA1-Constants |
||||
// initial hash values
|
||||
#define H0 0x67452301 |
||||
#define H1 0xEFCDAB89 |
||||
#define H2 0x98BADCFE |
||||
#define H3 0x10325476 |
||||
#define H4 0xC3D2E1F0 |
||||
// constants Kt
|
||||
#define K1 0x5A827999 |
||||
#define K2 0x6ED9EBA1 |
||||
#define K3 0x8F1BBCDC |
||||
#define K4 0xCA62C1D6 |
||||
#pragma endregion |
||||
|
||||
void printBits(size_t const size, void const* const ptr); |
||||
uint32_t leftRotate(uint32_t n, uint32_t d); |
||||
uint32_t SHA1_f1(uint32_t b, uint32_t c, uint32_t d); |
||||
uint32_t SHA1_f2(uint32_t b, uint32_t c, uint32_t d); |
||||
uint32_t SHA1_f3(uint32_t b, uint32_t c, uint32_t d); |
||||
uint32_t SHA1_f4(uint32_t b, uint32_t c, uint32_t d); |
||||
|
||||
void main(void) { |
||||
|
||||
int result = 0; |
||||
|
||||
printf("****** SHA1 preprocessing ******\n\n"); |
||||
#pragma region Preprocessing |
||||
|
||||
printf("------ Set initial hash value ------\n\n"); |
||||
#pragma region Initial Hash values |
||||
uint32_t a, b, c, d, e; |
||||
uint32_t h[5] = { H0, H1, H2, H3, H4 }; |
||||
uint32_t k[5] = { 0, K1, K2, K3, K4 }; // 5 so the array can be accessed by 1, 2, 3, 4
|
||||
a = h[0]; |
||||
b = h[1]; |
||||
c = h[2]; |
||||
d = h[3]; |
||||
e = h[4]; |
||||
|
||||
#pragma endregion |
||||
|
||||
if (sizeof(INPUT_MESSAGE) * 8 > 447) { |
||||
printf("Message too long!"); |
||||
return 1000002; |
||||
} |
||||
|
||||
printf("------ Padding message ------\n\n"); |
||||
#pragma region Padding |
||||
// print information about message without padding
|
||||
unsigned char messageNoPadding[] = INPUT_MESSAGE; |
||||
int numBytesMessage = (sizeof(INPUT_MESSAGE) - 1); // -1 because of '\0' at end of the string
|
||||
printf("Size of message without padding: %i bits\n", numBytesMessage*8); |
||||
printf("Message without padding\n"); |
||||
printBits(sizeof(messageNoPadding), &messageNoPadding); |
||||
|
||||
unsigned char message[BLOCK_LENGTH] = ""; |
||||
// fill in message
|
||||
for (uint32_t i = 0; i < numBytesMessage; i++) |
||||
{ |
||||
message[i] = INPUT_MESSAGE[i]; |
||||
} |
||||
// set bit
|
||||
message[numBytesMessage] = 0b10000000; |
||||
printf("\nMessage after adding 1: \n"); |
||||
printBits(sizeof(message), &message); |
||||
// add length with high and low byte (length is 64bit)
|
||||
message[BLOCK_LENGTH - 1] = INT_64_LOW_BYTE(numBytesMessage * 8); |
||||
message[BLOCK_LENGTH - 2] = INT_64_HIGH_BYTE(numBytesMessage * 8); |
||||
printf("\nMessage after adding length: \n"); |
||||
printBits(sizeof(message), &message); |
||||
#pragma endregion |
||||
|
||||
#pragma endregion |
||||
|
||||
printf("\n\n****** Hash computation ******\n\n"); |
||||
#pragma region Hash computation |
||||
|
||||
printf("\n------ Prepare message schedule ------\n\n"); |
||||
#pragma region Prepare message schedule |
||||
uint32_t WordArray[80] = { 0 }; |
||||
for (uint32_t i = 0; i < 16; i++) { |
||||
uint32_t currentbyte = message[i] << 24; |
||||
uint32_t tmp = (uint32_t)(((uint8_t)(message[i * 4]) << 24) + ((uint8_t)(message[4 * i + 1]) << 16) + ((uint8_t)(message[4 * i + 2]) << 8) + (uint8_t)(message[4 * i + 3])); |
||||
WordArray[i] = tmp; |
||||
} |
||||
for (uint32_t i = 16; i < 80; i++) { |
||||
WordArray[i] = leftRotate((WordArray[i - 3] ^ WordArray[i - 8] ^ WordArray[i - 14] ^ WordArray[i - 16]), 1); |
||||
} |
||||
#pragma endregion |
||||
|
||||
printf("\n------ Stages ------\n\n"); |
||||
#pragma region Stages calculations |
||||
uint32_t (*f_ptr)(uint32_t, uint32_t, uint32_t) = &SHA1_f1; // use: (*f_ptr)(b,c,d);
|
||||
uint8_t stage = 1; |
||||
// print header row
|
||||
printf("\tA\t\tB\t\tC\t\tD\t\tE\n"); |
||||
|
||||
// stage 1...4
|
||||
for (uint32_t t = 0; t < 80; t++) { |
||||
uint32_t T = leftRotate(a, 5) + ((*f_ptr)(b, c, d)) + e + k[stage] + WordArray[t]; |
||||
e = d; |
||||
d = c; |
||||
c = leftRotate(b, 30); |
||||
b = a; |
||||
a = T; |
||||
|
||||
// print row
|
||||
printf("t= %02d:\t%08X\t%08X\t%08X\t%08X\t%08X\t\n", t, a, b, c, d, e); |
||||
|
||||
// switch stages
|
||||
if (t == 19) { f_ptr = SHA1_f2; stage = 2; printf("Switched to stage 2.\n"); } |
||||
else if (t == 39) { f_ptr = SHA1_f3; stage = 3; printf("Switched to stage 3.\n"); } |
||||
else if (t == 59) { f_ptr = SHA1_f4; stage = 4; printf("Switched to stage 4.\n"); } |
||||
} |
||||
#pragma endregion |
||||
|
||||
printf("\n------ Intermediate hash calculation ------\n\n"); |
||||
#pragma region intermediate hash calculation |
||||
uint32_t summand[5] = { a, b, c, d, e }; |
||||
for (uint8_t i = 0; i < 5; i++) { |
||||
// calculate
|
||||
uint32_t h_new = summand[i] + h[i]; |
||||
// print
|
||||
printf("H[%i] = %08X + %08X = %08X\n", i, summand[i], h[i], h_new); |
||||
// set value
|
||||
h[i] = h_new; |
||||
} |
||||
|
||||
#pragma endregion |
||||
#pragma endregion |
||||
|
||||
printf("\n****** Resulting hash ******\n\n"); |
||||
for (uint8_t i = 0; i < 5; i++) { |
||||
printf("%X ", h[i]); |
||||
} |
||||
printf("\n\n"); |
||||
|
||||
return 0; |
||||
} |
||||
|
||||
uint32_t SHA1_f1(uint32_t b, uint32_t c, uint32_t d) { |
||||
return (b & c) | (~b & d); |
||||
} |
||||
|
||||
uint32_t SHA1_f2(uint32_t b, uint32_t c, uint32_t d) { |
||||
return b ^ c ^ d; |
||||
} |
||||
|
||||
uint32_t SHA1_f3(uint32_t b, uint32_t c, uint32_t d) { |
||||
return (b & c) | (b & d) | (c & d); |
||||
} |
||||
|
||||
uint32_t SHA1_f4(uint32_t b, uint32_t c, uint32_t d) { |
||||
return b ^ c ^ d; |
||||
} |
||||
|
||||
uint32_t leftRotate(uint32_t n, uint32_t d) |
||||
{ |
||||
/* In n<<d, last d bits are 0. To put first 3 bits of n at
|
||||
last, do bitwise or of n<<d with n >>(INT_BITS - d) */ |
||||
return (n << d) | (n >> (VALUE_LENGTH - d)); |
||||
} |
||||
|
||||
// Assumes little endian
|
||||
void printBits(size_t const size, void const* const ptr) |
||||
{ |
||||
unsigned char* b = (unsigned char*)ptr; |
||||
unsigned char byte; |
||||
int i, j; |
||||
|
||||
for (i = 0; i < size; i++) { |
||||
for (j = 7; j >= 0; j--) { |
||||
byte = (b[i] >> j) & 1; |
||||
printf("%u", byte); |
||||
} |
||||
} |
||||
/*original:
|
||||
for (i = size - 1; i >= 0; i--) { |
||||
for (j = 7; j >= 0; j--) { |
||||
byte = (b[i] >> j) & 1; |
||||
printf("%u", byte); |
||||
} |
||||
}*/ |
||||
puts(""); |
||||
} |
||||
@ -1,3 +0,0 @@ |
||||
# ASYD_DOCKER |
||||
|
||||
Git Repository für die Beispiele und Übungen des Docker-Teils von ASYD im FS 2023. |
||||
@ -1,37 +0,0 @@ |
||||
# Creates a simple .Net console application, writing second-tick counts to the terminal |
||||
# build with: docker build -t REP/IMAGE_NAME:TAG . |
||||
# run with: docker run --rm -it IMAGE_NAME <count_to> |
||||
# list intermediate imgs: docker images --filter label=stage=builder |
||||
|
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder |
||||
LABEL stage=builder |
||||
|
||||
WORKDIR /app |
||||
# Copy everything from src-directory on host to workdir in image |
||||
COPY src . |
||||
# Build and publish a release to directory "out" (build implicitly restores NuGet packages) |
||||
RUN dotnet publish -c Release -o out |
||||
|
||||
# uncomment for testing the build-env image |
||||
# CMD ["dotnet", "bin/Release/net7.0/DotnetDocker-01.dll"] |
||||
|
||||
# Build runtime image |
||||
# FROM mcr.microsoft.com/dotnet/aspnet:7.0 |
||||
FROM mcr.microsoft.com/dotnet/runtime:7.0 |
||||
# create user in the image |
||||
RUN groupadd -r mygroup && useradd --no-log-init --create-home --shell /bin/bash -r -g mygroup myuser |
||||
# change user |
||||
USER myuser |
||||
# make app-dir (WORKDIR cmd would create a dir owned by root -> permission denied!) |
||||
RUN mkdir /home/myuser/app |
||||
# set build- and run-time working directory |
||||
WORKDIR /home/myuser/app |
||||
COPY --chown=myuser:mygroup --from=builder /app/out . |
||||
# Opt-out of the diagnostic pipeline. This allows the container to run as read-only. |
||||
ENV COMPlus_EnableDiagnostics=0 |
||||
# |
||||
# CMD ["dotnet", "ASYD_Demo.dll"] |
||||
ENTRYPOINT ["dotnet", "ASYD_Demo.dll"] |
||||
|
||||
|
||||
|
||||
@ -1,5 +0,0 @@ |
||||
#!/bin/bash |
||||
docker build -t kaohslu/01-demo-img . |
||||
docker login |
||||
docker image push kaohslu/01-demo-img |
||||
echo "to run type: 'docker run --rm kaohslu/01-demo-img'" |
||||
@ -1,8 +0,0 @@ |
||||
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
||||
<PropertyGroup> |
||||
<OutputType>Exe</OutputType> |
||||
<TargetFramework>net7.0</TargetFramework> |
||||
</PropertyGroup> |
||||
|
||||
</Project> |
||||
@ -1,39 +0,0 @@ |
||||
using System; |
||||
using System.Threading; |
||||
|
||||
namespace ASYD_Demo { |
||||
internal class Program { |
||||
static void Main( string[] args ) { |
||||
|
||||
if( args.Length >= 1 && args[0] == "--help" ) { |
||||
PrintUsageAndExit(); |
||||
return; |
||||
} |
||||
|
||||
int a = args.Length >= 1 ? Convert.ToInt32( args[0] ) : -1; |
||||
int b = args.Length >= 2 ? Convert.ToInt32( args[1] ) : -1; |
||||
if( a > b ) { (a, b) = (b, a); } // swap so that a < b |
||||
|
||||
int counter = a >= 0 ? a : 1; |
||||
int to = b >= 0 ? b : int.MaxValue; |
||||
|
||||
Console.WriteLine( $"Counting from {counter} to {( to == int.MaxValue ? "2^32" : to )}" ); |
||||
|
||||
while( counter <= to ) { |
||||
Console.WriteLine( $"Counter: {counter++}" ); |
||||
if( counter <= to ) |
||||
Thread.Sleep( 1000 ); |
||||
} |
||||
} // end Main() |
||||
|
||||
public static void PrintUsageAndExit( int err = 0 ) { |
||||
Console.WriteLine( System.AppDomain.CurrentDomain.FriendlyName + " [[from] to]" ); |
||||
Console.WriteLine( " Counts in 1-second intervals . " + |
||||
"If specified, counts from \"from\" to \"to\" and exists, otherwise from 0 to 2^32." ); |
||||
System.Environment.Exit( err ); |
||||
|
||||
} // end Usage() |
||||
|
||||
} // end Program |
||||
} // end namespace |
||||
|
||||
@ -1,13 +0,0 @@ |
||||
# on host, create named container |
||||
```docker run -it --name 123deb debian``` |
||||
# in container, create file in /tmp |
||||
```echo "hallo ASYD" > /tmp/123.txt``` |
||||
# ... and exit from container |
||||
```exit``` |
||||
|
||||
# find the file by name starting in /var/lib/docker/ |
||||
```sudo find /var/lib/docker/ -name 123.txt``` |
||||
# print the file contents |
||||
```sudo cat $(sudo find /var/lib/docker/ -name 123.txt)``` |
||||
|
||||
|
||||
@ -1,34 +0,0 @@ |
||||
|
||||
# on host, first create a directory /user/home/data |
||||
|
||||
# on host, create a container with a host container in /mydata |
||||
```docker run --rm -it -v /home/pi/data/:/mydata debian``` |
||||
|
||||
# in container, change directory to volume |
||||
```cd /mydata``` |
||||
|
||||
# create the greeting |
||||
```echo "hi" > greetings.txt``` |
||||
# show created file |
||||
```ls -l``` |
||||
# output content of created file to console |
||||
```cat greetings.txt``` |
||||
# exit from container |
||||
```exit``` |
||||
|
||||
|
||||
# again on the host, create another container with a named container in /stillmydata |
||||
```cd /home/pi/data/``` |
||||
# show greetings-file in volume |
||||
```cat greetings.txt``` |
||||
|
||||
# need to change permissions before writing to file |
||||
```sudo chmod o+w greeting.txt``` |
||||
```echo " bye" >> greetings.txt``` |
||||
# exit from container |
||||
```cat greetings.txt``` |
||||
|
||||
# create a new container with a host container in /mydata |
||||
```docker run --rm -it -v /home/pi/data/:/stillmydata debian``` |
||||
# show greetings-file in volume |
||||
```cat /stillmydata/greetings.txt``` |
||||
@ -1,23 +0,0 @@ |
||||
# on host, create a container with a named container in /mydata |
||||
```docker run --rm -it -v myvolume:/mydata debian``` |
||||
|
||||
# in container, change directory to volume |
||||
```cd /mydata``` |
||||
|
||||
# create the greeting |
||||
```echo "hi from $(hostname)" > greetings.txt``` |
||||
# show created file |
||||
```ls -l``` |
||||
# output content of created file to console |
||||
```cat greetings.txt``` |
||||
# exit from container |
||||
```exit``` |
||||
|
||||
|
||||
# again on host, create another container with a named container in /stillmydata |
||||
```docker run --rm -it -v myvolume:/stillmydata debian``` |
||||
# show greetings-file in volume |
||||
```cat /stillmydata/greetings.txt``` |
||||
# exit from container |
||||
```exit``` |
||||
|
||||
@ -1,19 +0,0 @@ |
||||
#!/bin/bash |
||||
# get the container name from the current working directory |
||||
CNT_NAME=$(basename $(pwd)) |
||||
|
||||
echo "starting the nginx-webserver in a container named $IMGAE_NAME" |
||||
docker run -it --rm -d -p 8080:80 --name $CNT_NAME nginx |
||||
|
||||
# tell user what to do :) |
||||
echo "okay. now fire up browser and type 'http://$(hostname).simple.eee.intern:8080/' into address bar." |
||||
echo "you should see the nginx welcome page." |
||||
echo |
||||
read -n 1 -p "press any key to copy our web-page to to container." |
||||
docker cp index.html $CNT_NAME:/usr/share/nginx/html/ |
||||
echo "okay, done" |
||||
echo "now reload the page in your browser. you should see our web-page." |
||||
echo |
||||
read -n 1 -p "when done, press any key to stop (and remove) the webserver container." |
||||
docker stop $CNT_NAME |
||||
echo "sweet. bye!" |
||||
@ -1,8 +0,0 @@ |
||||
<html> |
||||
<head> <title>Hello ASYD!</title> </head> |
||||
<body> <h1>This is a Heading</h1> |
||||
This is some text. Don't you think Docker rocks? <p> |
||||
Anyways, you have just copied the file index.html from your host-computer (i.e., your Raspi) into a running container. Splendid! |
||||
</body> |
||||
</html> |
||||
|
||||
@ -1,11 +0,0 @@ |
||||
|
||||
Creates an Image with a static web-page using docker CLI commands |
||||
(not using a Dockerfile) |
||||
|
||||
- starts a container from the latest nginx image |
||||
- copies a static webpage to it using docker cp |
||||
- creates an image from the container using docker commit |
||||
- starts the newly created image |
||||
- cleans up on keypress after telling the user how to view the webpage |
||||
|
||||
|
||||
@ -1,40 +0,0 @@ |
||||
#!/bin/bash |
||||
|
||||
# use the base of the current working directory as the new image name (e.g., "webimg:v1") |
||||
IMAGE_NAME=$(basename $(pwd)):v1 |
||||
|
||||
# creates an image "myweb:v1" by commiting a container. |
||||
# start with "./build.sh" in current directory |
||||
|
||||
# create a random container name and use throuout this scrip |
||||
CNTR=$(date | md5sum | head -c 10) |
||||
|
||||
echo "working with container name '$CNTR'" |
||||
|
||||
if [ "$(docker ps -q -f name=$CNTR)" ]; then echo "container '$CNTR' exists, exiting"; exit 1; fi |
||||
|
||||
# create nginx-container named web |
||||
docker run -it --rm -d -p 8080:80 --name $CNTR nginx |
||||
|
||||
# copy static webpage into container |
||||
docker cp index.html $CNTR:/usr/share/nginx/html/ |
||||
|
||||
# commit running container to image |
||||
docker commit $CNTR $IMAGE_NAME |
||||
|
||||
# stop container (which will also delete the container because of --rm ) |
||||
docker stop $CNTR |
||||
|
||||
# start new container from image myweb:v1 and expose port 80 to 8080 on host |
||||
docker run -it --rm -d -p 8080:80 --name $CNTR $IMAGE_NAME |
||||
|
||||
# tell user what to do :) |
||||
echo "fire up browser and type 'http://$(hostname).simple.eee.intern:8080/' into address bar" |
||||
echo "you should see our webpage" |
||||
echo |
||||
read -n 1 -p "when done, press any key to stop (and remove) the webserver container." |
||||
echo |
||||
echo "stopping container $CNTR and cleaning up, hang on...." |
||||
docker stop $CNTR |
||||
|
||||
echo "done. bye then" |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> <title>Hello ASYD!</title> </head> |
||||
<body> <h1>This is a Heading</h1> |
||||
This is some text. |
||||
</body> |
||||
</html> |
||||
@ -1,6 +0,0 @@ |
||||
FROM gcc |
||||
WORKDIR /myapp |
||||
COPY hello-world.c . |
||||
RUN gcc -o hello-world hello-world.c |
||||
CMD ["/myapp/hello-world"] |
||||
|
||||
@ -1,23 +0,0 @@ |
||||
#!/bin/bash |
||||
# get the image name from the current working directory |
||||
IMG_NAME=$(basename $(pwd)) |
||||
# create a random container name and use throuout this scrip |
||||
CNTR=$(date | md5sum | head -c 10) |
||||
|
||||
docker build -t $IMG_NAME . |
||||
echo "starting the container with: 'docker run --rm $IMG_NAME'" |
||||
|
||||
echo "creating a container with: 'docker create --name $CTNR $IMG_NAME'" |
||||
docker create --name $CNTR $IMG_NAME |
||||
|
||||
echo "copying /myapp from container to host: 'docker cp $CNTR:/myapp/hello-world .'" |
||||
docker cp $CNTR:/myapp/hello-world . |
||||
|
||||
echo "removing the container with: 'docker rm $CTNR'" |
||||
docker rm $CNTR |
||||
|
||||
echo "starting hello-world from the host: './hello-world'" |
||||
./hello-world |
||||
|
||||
|
||||
# echo "to start a bash in the container, run: 'docker run --rm -it $IMG_NAME bash'" |
||||
Binary file not shown.
@ -1,6 +0,0 @@ |
||||
#include <stdio.h> |
||||
int main() { |
||||
printf("Hello World from within my very own Docker Container :)\n"); |
||||
return 0; |
||||
} // end main()
|
||||
|
||||
@ -1,4 +0,0 @@ |
||||
# file Dockerfile |
||||
FROM debian |
||||
COPY greetings.txt /tmp |
||||
|
||||
@ -1,17 +0,0 @@ |
||||
#!/bin/bash |
||||
# get the container name from the current working directory |
||||
IMG_NAME=$(basename $(pwd)) |
||||
|
||||
docker build -t $IMG_NAME . |
||||
|
||||
echo "In the image do:" |
||||
echo " cd /tmp" |
||||
echo " ls -l" |
||||
echo " cat greetings.txt" |
||||
|
||||
|
||||
docker run --rm -it $IMG_NAME |
||||
|
||||
# can also string together commands to execute at container-start |
||||
# docker run --rm -it $IMG_NAME sh -c "cat /tmp/greetings.txt; ls -l /tmp/greetings.txt" |
||||
|
||||
@ -1 +0,0 @@ |
||||
hi there! |
||||
@ -1,3 +0,0 @@ |
||||
# file Dockerfile |
||||
FROM debian |
||||
RUN echo "hallo ASYD" > /tmp/greetings.txt |
||||
@ -1,17 +0,0 @@ |
||||
#!/bin/bash |
||||
# get the container name from the current working directory |
||||
IMG_NAME=$(basename $(pwd)) |
||||
|
||||
docker build -t $IMG_NAME . |
||||
|
||||
echo "In the image do:" |
||||
echo " cd /tmp" |
||||
echo " ls -l" |
||||
echo " cat greetings.txt" |
||||
|
||||
|
||||
docker run --rm -it $IMG_NAME |
||||
|
||||
# can also string together commands to execute at container-start |
||||
# docker run --rm -it $IMG_NAME sh -c "cat /tmp/greetings.txt; ls -l /tmp/greetings.txt" |
||||
|
||||
@ -1,3 +0,0 @@ |
||||
# file Dockerfile |
||||
FROM debian |
||||
RUN echo "hallo ASYD" > /tmp/greetings.txt && echo "bye, bye" > /tmp/bye.txt |
||||
@ -1,17 +0,0 @@ |
||||
#!/bin/bash |
||||
# get the container name from the current working directory |
||||
IMG_NAME=$(basename $(pwd)) |
||||
|
||||
docker build -t $IMG_NAME . |
||||
|
||||
echo "In the image do:" |
||||
echo " cd /tmp" |
||||
echo " ls -l" |
||||
echo " cat greetings.txt" |
||||
|
||||
|
||||
docker run --rm -it $IMG_NAME |
||||
|
||||
# can also string together commands to execute at container-start |
||||
# docker run --rm -it $IMG_NAME sh -c "cat /tmp/greetings.txt; ls -l /tmp/greetings.txt" |
||||
|
||||
@ -1,3 +0,0 @@ |
||||
# file Dockerfile |
||||
FROM debian |
||||
RUN echo "hallo ASYD" > /tmp/greetings.txt |
||||
@ -1,17 +0,0 @@ |
||||
#!/bin/bash |
||||
# get the container name from the current working directory |
||||
IMG_NAME=$(basename $(pwd)) |
||||
|
||||
docker build -t $IMG_NAME . |
||||
|
||||
echo "In the image do:" |
||||
echo " cd /tmp" |
||||
echo " ls -l" |
||||
echo " cat greetings.txt" |
||||
|
||||
|
||||
docker run --rm -it $IMG_NAME |
||||
|
||||
# can also string together commands to execute at container-start |
||||
# docker run --rm -it $IMG_NAME sh -c "cat /tmp/greetings.txt; ls -l /tmp/greetings.txt" |
||||
|
||||
@ -1,8 +0,0 @@ |
||||
# file Dockerfile |
||||
FROM debian |
||||
RUN mkdir /mydata && \ |
||||
echo "hi there!" > /mydata/greetings.txt && \ |
||||
apt-get update && apt-get install -y nano && apt-get clean && \ |
||||
rm -rf /var/lib/apt/lists/* |
||||
CMD ["nano", "/mydata/greetings.txt"] |
||||
|
||||
@ -1,7 +0,0 @@ |
||||
#!/bin/bash |
||||
# get the container name from the current working directory |
||||
IMG_NAME=$(basename $(pwd)) |
||||
|
||||
docker build -t $IMG_NAME . |
||||
|
||||
docker run --rm -it $IMG_NAME |
||||
@ -1 +0,0 @@ |
||||
hi there! |
||||
@ -1,6 +0,0 @@ |
||||
# file Dockerfile |
||||
FROM debian |
||||
WORKDIR /mydata |
||||
RUN echo "hi there!" > greetings.txt |
||||
# the created file is in /mydata/greetings.txt |
||||
|
||||
@ -1,20 +0,0 @@ |
||||
#!/bin/bash |
||||
# get the image name from the current working directory |
||||
IMG_NAME=$(basename $(pwd)) |
||||
|
||||
# create a random container name and use throuout this scrip |
||||
CNTR=$(date | md5sum | head -c 10) |
||||
|
||||
|
||||
docker build -t $IMG_NAME . |
||||
|
||||
# create container without running it |
||||
docker create --name $CNTR $IMG_NAME |
||||
# copy the file to working directory of the host |
||||
docker cp $CNTR:/mydata/greetings.txt . |
||||
# remove container again |
||||
docker rm $CNTR |
||||
|
||||
# now list new file |
||||
ls -l greetings.txt |
||||
|
||||
@ -1,17 +0,0 @@ |
||||
#!/bin/bash |
||||
# get the container name from the current working directory |
||||
IMG_NAME=$(basename $(pwd)) |
||||
|
||||
docker build -t $IMG_NAME . |
||||
|
||||
echo "In the image do:" |
||||
echo " cd /tmp" |
||||
echo " ls -l" |
||||
echo " cat greetings.txt" |
||||
|
||||
|
||||
docker run --rm -it $IMG_NAME |
||||
|
||||
# can also string together commands to execute at container-start |
||||
# docker run --rm -it $IMG_NAME sh -c "cat /tmp/greetings.txt; ls -l /tmp/greetings.txt" |
||||
|
||||
@ -1,4 +0,0 @@ |
||||
# file Dockerfile |
||||
FROM debian |
||||
COPY greetings.txt /tmp |
||||
|
||||
@ -1 +0,0 @@ |
||||
hi there! |
||||
@ -1,6 +0,0 @@ |
||||
# Datei Dockerfile |
||||
FROM debian |
||||
WORKDIR /app |
||||
COPY hello-world . |
||||
CMD ["/app/hello-world"] |
||||
|
||||
Binary file not shown.
@ -1,11 +0,0 @@ |
||||
|
||||
Creates an Image with a static web-page using docker CLI commands |
||||
(not using a Dockerfile) |
||||
|
||||
- starts a container from the latest nginx image |
||||
- copies a static webpage to it using docker cp |
||||
- creates an image from the container using docker commit |
||||
- starts the newly created image |
||||
- cleans up on keypress after telling the user how to view the webpage |
||||
|
||||
|
||||
@ -1,34 +0,0 @@ |
||||
#!/bin/bash |
||||
|
||||
# creates an image "myweb:v1" by commiting a container. |
||||
# start with "./build.sh" in current directory |
||||
|
||||
# create a random container name and use throuout this scrip |
||||
CNTR=$(date | md5sum | head -c 10) |
||||
|
||||
echo "working with container name '$CNTR'" |
||||
|
||||
if [ "$(docker ps -q -f name=$CNTR)" ]; then echo "container '$CNTR' exists, exiting"; exit 1; fi |
||||
|
||||
# create nginx-container named web |
||||
docker run -it --rm -d -p 8080:80 --name $CNTR nginx |
||||
|
||||
# copy static webpage into container |
||||
docker cp index.html $CNTR:/usr/share/nginx/html/ |
||||
|
||||
# commit running container to image |
||||
docker commit $CNTR myweb:v1 |
||||
|
||||
# stop container (which will also delete the container because of --rm ) |
||||
docker stop $CNTR |
||||
|
||||
# start new container from image myweb:v1 and expose port 80 to 8080 on host |
||||
docker run -it --rm -d -p 8080:80 --name $CNTR myweb:v1 |
||||
|
||||
# tell user what to do :) |
||||
echo "fire up browser and type 'http://$(hostname).simple.eee.intern:8080/' into address bar" |
||||
read -n 1 -p "when done, press any key to stop (and remove) the webserver container." |
||||
echo "stopping container $CNTR and cleaning up, hang on...." |
||||
docker stop $CNTR |
||||
|
||||
echo "done. bye then :)" |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> <title>Hello ASYD!</title> </head> |
||||
<body> <h1>This is a Heading</h1> |
||||
This is some text. |
||||
</body> |
||||
</html> |
||||
@ -1,5 +0,0 @@ |
||||
# Datei Dockerfile |
||||
FROM nginx |
||||
COPY index.html /usr/share/nginx/html/ |
||||
|
||||
|
||||
@ -1,3 +0,0 @@ |
||||
#!/bin/bash |
||||
docker build -t myweb:v2 . |
||||
|
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> <title>Hello ASYD!</title> </head> |
||||
<body> <h1>This is a Heading</h1> |
||||
This is some text. |
||||
</body> |
||||
</html> |
||||
@ -1,5 +0,0 @@ |
||||
# Datei Dockerfile |
||||
FROM debian |
||||
RUN apt-get update |
||||
RUN apt-get install -y nano |
||||
|
||||
@ -1,3 +0,0 @@ |
||||
#!/bin/bash |
||||
docker build -t nanodeb:v1 . |
||||
|
||||
@ -1,7 +0,0 @@ |
||||
# Datei Dockerfile |
||||
FROM debian |
||||
RUN apt-get update && \ |
||||
apt-get install -y nano && \ |
||||
apt-get clean && \ |
||||
rm -rf /var/lib/apt/lists/* |
||||
|
||||
@ -1,3 +0,0 @@ |
||||
#!/bin/bash |
||||
docker build -t nanodeb:v2 . |
||||
|
||||
@ -1,8 +0,0 @@ |
||||
# Datei Dockerfile |
||||
FROM debian |
||||
RUN apt-get update && \ |
||||
apt-get install -y nano && \ |
||||
apt-get clean && \ |
||||
rm -rf /var/lib/apt/lists/* |
||||
CMD ["nano", "/greeting.txt"] |
||||
|
||||
@ -1,3 +0,0 @@ |
||||
#!/bin/bash |
||||
docker build -t nanodeb:v3 . |
||||
|
||||
@ -1,9 +0,0 @@ |
||||
# Datei Dockerfile |
||||
FROM debian |
||||
RUN apt-get update && \ |
||||
apt-get install -y nano && \ |
||||
apt-get clean && \ |
||||
rm -rf /var/lib/apt/lists/* |
||||
ENTRYPOINT ["nano"] |
||||
CMD ["/greeting.txt"] |
||||
|
||||
@ -1,3 +0,0 @@ |
||||
#!/bin/bash |
||||
docker build -t nanodeb:v4 . |
||||
|
||||
@ -1,10 +0,0 @@ |
||||
# Datei Dockerfile |
||||
FROM debian |
||||
RUN apt-get update && \ |
||||
apt-get install -y nano && \ |
||||
apt-get clean && \ |
||||
rm -rf /var/lib/apt/lists/* |
||||
WORKDIR /app |
||||
ENTRYPOINT ["nano"] |
||||
CMD ["/greeting.txt"] |
||||
|
||||
@ -1,3 +0,0 @@ |
||||
#!/bin/bash |
||||
docker build -t nanodeb:v5 . |
||||
|
||||
@ -1,4 +0,0 @@ |
||||
FROM scratch |
||||
COPY hello-world2 / |
||||
CMD ["/hello-world2"] |
||||
|
||||
@ -1,5 +0,0 @@ |
||||
#!/bin/bash |
||||
docker build -t myscratch . |
||||
|
||||
echo "running with: 'docker run --rm myscratch'" |
||||
docker run --rm myscratch |
||||
Binary file not shown.
Binary file not shown.
@ -1,15 +0,0 @@ |
||||
#!/bin/bash |
||||
docker run -it --rm -d -p 8080:80 --name webcp nginx |
||||
|
||||
# tell user what to do :) |
||||
echo "okay, fire up browser and type 'http://$(hostname).simple.eee.intern:8080/' into address bar." |
||||
echo "you should see the nginx welcome page." |
||||
echo |
||||
read -n 1 -p "then press any key to copy our web-page to to container." |
||||
docker cp index.html web:/usr/share/nginx/html/ |
||||
echo "okay, done" |
||||
echo "now reload the page in your browser. you should see our web-page." |
||||
echo |
||||
read -n 1 -p "when done, press any key to stop (and remove) the webserver container." |
||||
docker stop webcp |
||||
echo "sweet. bye" |
||||
@ -1,6 +0,0 @@ |
||||
<html> |
||||
<head> <title>Hello ASYD!</title> </head> |
||||
<body> <h1>This is a Heading</h1> |
||||
This is some text. |
||||
</body> |
||||
</html> |
||||
@ -1,10 +0,0 @@ |
||||
# file Dockerfile |
||||
FROM debian |
||||
|
||||
RUN apt-get update && apt-get install -y netcat |
||||
WORKDIR /app |
||||
COPY start_cmd.sh . |
||||
RUN mkfifo /app/netcat_fifo |
||||
RUN echo "hi there" |
||||
CMD ["/app/start_cmd.sh"] |
||||
|
||||
@ -1,6 +0,0 @@ |
||||
#!/bin/bash |
||||
IMAGE_NAME=$(basename $(pwd)) |
||||
docker build -t $IMAGE_NAME . |
||||
echo |
||||
echo "run with: 'docker run --rm -p4321:1234 $IMAGE_NAME'" |
||||
echo "on host start: 'nc host.example.com 4321'" |
||||
@ -1,10 +0,0 @@ |
||||
# file docker-compose.yml |
||||
version: '3' |
||||
|
||||
services: |
||||
nc-server: |
||||
# image: netcat_server |
||||
build: . |
||||
restart: unless-stopped |
||||
ports: |
||||
- "4321:1234" |
||||
@ -1,3 +0,0 @@ |
||||
#!/bin/bash |
||||
cat /app/netcat_fifo | /bin/sh -i 2>&1 | nc -l 1234 > /app/netcat_fifo |
||||
|
||||
@ -1,11 +0,0 @@ |
||||
FROM golang:1.13 AS build |
||||
|
||||
WORKDIR /compose/hello-docker |
||||
COPY main.go main.go |
||||
RUN CGO_ENABLED=0 go build -o backend main.go |
||||
|
||||
FROM scratch |
||||
COPY --from=build /compose/hello-docker/backend /usr/local/bin/backend |
||||
CMD ["/usr/local/bin/backend"] |
||||
|
||||
|
||||
@ -1,30 +0,0 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"fmt" |
||||
"log" |
||||
"net/http" |
||||
) |
||||
|
||||
func handler(w http.ResponseWriter, r *http.Request) { |
||||
fmt.Println(r.URL.RawQuery) |
||||
fmt.Fprintf(w, ` |
||||
## . |
||||
## ## ## == |
||||
## ## ## ## ## === |
||||
/"""""""""""""""""\___/ === |
||||
{ / ===- |
||||
\______ O __/ |
||||
\ \ __/ |
||||
\____\_______/ |
||||
|
||||
|
||||
Hello from Docker! |
||||
|
||||
`) |
||||
} |
||||
|
||||
func main() { |
||||
http.HandleFunc("/", handler) |
||||
log.Fatal(http.ListenAndServe(":80", nil)) |
||||
} |
||||
@ -1,9 +0,0 @@ |
||||
services: |
||||
frontend: |
||||
build: frontend |
||||
ports: |
||||
- 80:80 |
||||
depends_on: |
||||
- backend |
||||
backend: |
||||
build: backend |
||||
@ -1,4 +0,0 @@ |
||||
FROM nginx:alpine |
||||
COPY nginx.conf /etc/nginx/conf.d/default.conf |
||||
|
||||
|
||||
@ -1,6 +0,0 @@ |
||||
server { |
||||
listen 80; |
||||
location / { |
||||
proxy_pass http://backend:80; |
||||
} |
||||
} |
||||
@ -1,32 +0,0 @@ |
||||
# Datei test/docker-compose.yml |
||||
version: '3' |
||||
|
||||
services: |
||||
db: |
||||
image: mariadb:latest |
||||
volumes: |
||||
- vol-db:/var/lib/mysql |
||||
environment: |
||||
MYSQL_RANDOM_ROOT_PASSWORD: 1 |
||||
MYSQL_DATABASE: wp |
||||
MYSQL_USER: wpuser |
||||
MYSQL_PASSWORD: geheim |
||||
restart: unless-stopped |
||||
|
||||
wordpress: |
||||
image: wordpress:latest |
||||
volumes: |
||||
- vol-www:/var/www/html/wp-content |
||||
ports: |
||||
- "8082:80" |
||||
environment: |
||||
WORDPRESS_DB_HOST: db:3306 |
||||
WORDPRESS_DB_USER: wpuser |
||||
WORDPRESS_DB_NAME: wp |
||||
WORDPRESS_DB_PASSWORD: geheim |
||||
restart: unless-stopped |
||||
|
||||
volumes: |
||||
vol-www: |
||||
vol-db: |
||||
|
||||
@ -1,3 +0,0 @@ |
||||
# file: Dockerfile |
||||
FROM alpine |
||||
RUN echo "hallo asyd" |
||||
@ -1,4 +0,0 @@ |
||||
FROM alpine |
||||
|
||||
RUN touch /tmp/xyz.txt |
||||
|
||||
@ -1,4 +0,0 @@ |
||||
FROM alpine |
||||
|
||||
RUN echo "hallo asyd" > /tmp/xyz.txt |
||||
|
||||
@ -1,24 +0,0 @@ |
||||
#!/bin/bash |
||||
IMAGE_NAME=$(basename $(pwd)) |
||||
|
||||
echo "***" |
||||
echo "*** creating an image from Dockerfile.v1 with name my_alpine" |
||||
|
||||
docker build . -f Dockerfile.v1 -t $IMAGE_NAME |
||||
|
||||
echo "***" |
||||
echo "***listing all images" |
||||
docker image ls |
||||
|
||||
read -n 1 -p "press any key to create an image with the same name from a slightly changed Dockerfile.v2" |
||||
|
||||
docker build . -f Dockerfile.v2 -t $IMAGE_NAME |
||||
|
||||
echo "***" |
||||
echo "*** listing all images" |
||||
docker image ls |
||||
|
||||
echo "***" |
||||
echo "*** note the 'dangling' image named <none>:<none>" |
||||
echo "*** to list only dangling images use: docker images --filter dangling=true" |
||||
docker images --filter dangling=true |
||||
@ -1,15 +0,0 @@ |
||||
FROM alpine as builder |
||||
|
||||
# install gcc |
||||
RUN apk update && apk add gcc musl-dev |
||||
|
||||
WORKDIR /app |
||||
COPY hello-world.c /app |
||||
RUN gcc -o hello-world hello-world.c |
||||
|
||||
FROM alpine |
||||
|
||||
WORKDIR /app |
||||
COPY --from=builder /app/hello-world /app |
||||
CMD ["/app/hello-world"] |
||||
|
||||
@ -1,11 +0,0 @@ |
||||
#!/bin/bash |
||||
|
||||
IMAGE_NAME=$(basename $(pwd)) |
||||
|
||||
echo "***" |
||||
echo "*** building image with: 'docker build . -t $IMAGE_NAME'" |
||||
|
||||
|
||||
docker build . -t $IMAGE_NAME |
||||
echo "***" |
||||
echo "*** run with: 'docker run --rm $IMAGE_NAME'" |
||||
Binary file not shown.
@ -1,6 +0,0 @@ |
||||
#include <stdio.h> |
||||
int main() { |
||||
printf("Hello World from within my very own Docker Container :)\n"); |
||||
return 0; |
||||
} // end main()
|
||||
|
||||
@ -1,13 +0,0 @@ |
||||
|
||||
|
||||
Start the SDK--container interactively, mounting the current directory as /app in the container |
||||
$ docker run --rm -it -v $(pwd):/app mcr.microsoft.com/dotnet/sdk:5.0 |
||||
|
||||
Change to folder ./app which contains the ./src folder (/app/src) |
||||
# cd /app |
||||
|
||||
Start the build using /app/src as source folder and writing to /app/out |
||||
# dotnet publish -c Release -o out src |
||||
|
||||
That's it, exit |
||||
# exit |
||||
@ -1,8 +0,0 @@ |
||||
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
||||
<PropertyGroup> |
||||
<OutputType>Exe</OutputType> |
||||
<TargetFramework>net7.0</TargetFramework> |
||||
</PropertyGroup> |
||||
|
||||
</Project> |
||||
@ -1,11 +0,0 @@ |
||||
# file: Dockerfile |
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder |
||||
|
||||
WORKDIR /app |
||||
# Copy everything from src-directory on host to workdir in image |
||||
|
||||
COPY src . |
||||
# Build and publish a release to directory "out" (build implicitly restores NuGet packages) |
||||
RUN dotnet publish -c Release -o out |
||||
|
||||
CMD ["dotnet", "/app/out/ConsoleApp1.dll"] |
||||
@ -1,10 +0,0 @@ |
||||
!/bin/bash |
||||
IMAGE_NAME=$(basename $(pwd)) |
||||
|
||||
echo "***" |
||||
echo "*** buildig image with: 'docker build . -t $IMAGE_NAME'" |
||||
docker build . -t $IMAGE_NAME |
||||
|
||||
echo "***" |
||||
echo "*** start image with: 'docker run --rm -t $IMAGE_NAME'" |
||||
docker run --rm -t $IMAGE_NAME |
||||
@ -1,8 +0,0 @@ |
||||
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
||||
<PropertyGroup> |
||||
<OutputType>Exe</OutputType> |
||||
<TargetFramework>net7.0</TargetFramework> |
||||
</PropertyGroup> |
||||
|
||||
</Project> |
||||
@ -1,23 +0,0 @@ |
||||
# file: Dockerfile |
||||
FROM mcr.microsoft.com/dotnet/sdk:7.0 AS builder |
||||
|
||||
WORKDIR /app |
||||
|
||||
# Copy everything from src-directory on host to workdir in image |
||||
COPY src . |
||||
|
||||
# Build and publish a release to directory "out" (build implicitly restores NuGet packages) |
||||
RUN dotnet publish -c Release -o out |
||||
|
||||
# Build runtime image |
||||
FROM mcr.microsoft.com/dotnet/runtime:7.0 |
||||
|
||||
# install GPIO library (don't clean, need cache :-) |
||||
RUN apt-get -y update && apt-get -y install gpiod libgpiod2 libgpiod-dev |
||||
|
||||
# set build- and run-time working directory |
||||
WORKDIR /app |
||||
|
||||
COPY --from=builder /app/out /app |
||||
|
||||
CMD ["dotnet", "/app/ConsoleApp1.dll"] |
||||
@ -1,11 +0,0 @@ |
||||
#!/bin/bash |
||||
IMAGE_NAME=$(basename $(pwd)) |
||||
|
||||
echo "***" |
||||
echo "*** buildig image with: 'docker build . -t $IMAGE_NAME'" |
||||
docker build . -t $IMAGE_NAME |
||||
|
||||
|
||||
echo "***" |
||||
echo "*** start image with: 'docker run --rm --device /dev/gpiochip0 $IMAGE_NAME'" |
||||
docker run --rm $IMAGE_NAME |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue