Skip to content

gorankarlic/lecture-dlt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

⛓️ Blockchain Lab

1. Download and Install Docker

https://www.docker.com/get-started

Start the newly installed Docker application.

2. Run Debian linux

2.1 Mac

Open the Terminal (Terminal) app and run:

docker run -it debian

2.2 Windows

2.2.1 Instal Terminal app

It is recommended that you install the Terminal app for Windows available at:

https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701

Open the Terminal (Terminal) app and run:

docker run -it debian

Reuse a previous container

Or to reuse your a previously started container run:

docker attach $(docker start $(docker ps -l -q))

2.3 Command prompt

You will evenutually see a line similar to this:

root@5555b7f58ebe:/#

This is the command prompt of the Debian operating system that is now running within a container on your computer.

2.3.1 Verify

Type the following command to show the Debian version:

cat /etc/os-release

It should output Debian GNU/Linux 12 (bookworm) amongt other information.

3. Install Ethereum client

3.1 Install wget

wget is a utility which can download files from the internet. To install wget run:

apt-get update && apt-get install -y wget

3.2 Download geth

geth is the most popular Ethereum client. It is written in the Go programming language.

To download geth,

if you have processor with an x64 architecture (e.g., AMD, Intel), run:

cd && wget -O geth.tar.gz https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-amd64-1.13.4-3f907d6a.tar.gz

if you have processor with an ARM architecture (e.g., Apple M1), run:

cd && wget -O geth.tar.gz https://gethstore.blob.core.windows.net/builds/geth-alltools-linux-arm64-1.13.4-3f907d6a.tar.gz

3.3 Install geth

To unpack and install then downloaded program files run:

cd && tar -xvf geth.tar.gz --exclude=COPYING --strip-components=1 && rm geth.tar.gz && chmod u+x * && mv * /usr/bin

3.4 Verify result

Type the following command to show the location of the geth program:

which geth

It should output /usr/bin/geth.

4. 🥨 "Look ma, I gots them blockchains!"

4.1 Run your own Ethereum node

You are now ready to participate in the Ethereum network. To start you local node run:

geth

If you follow the output, you will notice that your node will do the following:

  1. Find peers
  2. Once found, it will start downloading a local copy of the blockchain

If it fails to find any peers, it might be because your operating system firewall or the network is blocking the connections.

Try following:

  1. Connect to a less restrictive network, like your mobile phone hotspot
  2. ⚠️ Temporarily disable the firewall in the operating system settings (do not forget to enable the firewall after lab session)

If you want to stop your node press CTRL+C.

4.2 Interact with the blockchain using your Ethereum node CLI

To interact with the blockchain using your Ethereum node's CLI (command line interface a.k.a. console) run:

geth --syncmode light --verbosity 1 console

You can find the reference for the console commands in the Web3 documentation.

4.2.1 View peers

To view the peer nodes that you are currently connected to:

admin.peers

You will notice that each peer has a remote IP address (here the IP address is 94.176.237.140):

remoteAddress: "94.176.237.140:30303"

You can query the peer's IP address using a Geolocation tool to find out where they are.

4.2.2 View blocks

Take a look at block number 3:

eth.getBlock(3)

Take a look at the latest block number:

eth.blockNumber

Take a look at the latest block:

eth.getBlock(eth.blockNumber)

4.2.3 View some funny stuff in block number 14000

Block number 14000 has an interesting message in it's extra data:

web3.toAscii(eth.getBlock(14000).extraData)

Now take look at the extra data in the latest block:

web3.toAscii(eth.getBlock(eth.blockNumber).extraData)

4.2.4 Dive deeper into block transactions

Take a look at block 1000000:

eth.getBlock(1000000)

Block 1000000 has two transactions. Take a look at the first transaction in that block:

eth.getTransaction("0xea1093d492a1dcb1bef708f771a99a96ff05dcab81ca76c31940300177fcf49f")

Take a look at how much Ether the account that mined the last block has:

web3.fromWei(eth.getBalance(eth.getBlock(eth.blockNumber).miner), "Ether")

4.2.5 Create a new account

Create a new account:

personal.newAccount()

4.2.6 Exit the Geth console

Exit the console:

exit

✉️ Crypto Lab

1. Install Docker

On Mac:

https://download.docker.com/mac/stable/Docker.dmg

On Windows:

https://download.docker.com/win/stable/Docker%20Desktop%20Installer.exe

2. Run Debian linux

2.1 Mac

Open the Terminal (Terminal) app and run:

docker run -it debian

2.2 Windows

2.2.1 Instal Terminal app

It is recommended that you install the Terminal app for Windows available at:

https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701

2.2.2 Run

Open the Terminal (Terminal) app and run:

docker run -it debian

2.3 Install OpenSSL

Install the cryptographic library OpenSSL:

apt-get update && apt-get install -y openssl

3. 🔑 Symetric key cryptography

Encrypt and decrypt a plaintext message with symetric key cryptography.

3.1 Plaintext message

3.1.1 Create a message file

Create a file with a message:

echo Attack at 5:00 > message.txt

3.1.2 Read the message file

Read the file with a message:

cat message.txt

3.2 Encryption and decryption

3.2.1 Encrypt message

Encrypt the message:

openssl enc -AES-256-CBC -base64 -pbkdf2 -in message.txt -out encrypted.txt -p -pass pass:password

3.2.2 Show encrypted ciphertext

Show the encrypted ciphertext:

cat encrypted.txt

3.2.3 Decrypt the ciphertext

Decrypt the ciphertext:

openssl enc -AES-256-CBC -base64 -pbkdf2 -in encrypted.txt -out decrypted.txt -p -pass pass:password -d

3.2.4 Show decrypted message

Show the decrypted message:

cat decrypted.txt

4. 🔐 Asymetric (a.k.a. public / private key) cryptography using RSA

Encrypt and decrypt a plaintext message using the RSA (Rivest–Shamir–Adleman) public / private key cryptography.

4.1 Plaintext message

4.1.1 Create a message file

Create a file with a message:

echo Retreat at 6:00 > message.txt

4.1.2 Read the message file

Read the file with a message:

cat message.txt

4.2 Create a RSA key pair

4.2.1 Create a private key

Create a private key:

openssl genpkey -algorithm RSA -out private.txt

4.2.1 View the private key

View the created private key:

cat private.txt

4.2.3 Derive public key

Derive a public key:

openssl rsa -pubout -in private.txt -out public.txt

4.2.4 View the public key

View the created public key:

cat public.txt

4.3 Encryption and decryption

4.3.1 Encrypt message

Encrypt the message using the public key:

openssl pkeyutl -encrypt -pubin -inkey public.txt -in message.txt -out encrypted.bin

4.3.2 Show encrypted ciphertext

Show the encrypted ciphertext:

base64 encrypted.bin

4.3.3 Decrypt the ciphertext

Decrypt the ciphertext using the private key:

openssl pkeyutl -decrypt -inkey private.txt -in encrypted.bin -out decrypted.txt

4.3.4 Show decrypted message

Show the decrypted message:

cat decrypted.txt

5. 🔏Asymetric (a.k.a. public / private key) cryptography using EC

Sign and verify a plaintext message using EC (Elliptic-curve) public / private key cryptography.

5.1 Plaintext message

5.1.1 Create a message file

Create a file with a message:

echo Send 1 million USD to John Smith > message.txt

5.1.2 Read the message file

Read the file with a message:

cat message.txt

5.2 Create a EC key pair

5.2.1 Create a private key

Create a private key:

openssl ecparam -name secp256k1 -genkey -noout -out private.txt

5.2.2 View the private key

View the created private key:

cat private.txt

5.2.3 Derive public key

Derive a public key:

openssl ec -pubout -in private.txt -out public.txt

5.2.4 View the public key

View the created public key:

cat public.txt

5.3 Sign and verify

5.3.1 Sign message

Sign the message using the private key:

openssl dgst -sha256 -sign private.txt -out signature.bin message.txt

5.3.2 Show signature

Show the message signature:

base64 signature.bin

5.3.3 Verify the signature

Verify the signature using the public key:

openssl dgst -sha256 -verify public.txt -signature signature.bin message.txt

5.3.4 Alter message

Alter the message:

echo Send 2 million USD to John Smith > message.txt

5.3.5 Verify the signature again

Verify the signature using the public key:

openssl dgst -sha256 -verify public.txt -signature signature.bin message.txt

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published