Skip to content

Commit a998a3b

Browse files
committed
first cut mkdocs build with doctests.
1 parent edc1e17 commit a998a3b

23 files changed

+722
-150
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ psql.sh
66
.cache
77
test/
88
example/
9+
.virt

.github/workflows/jekyll-gh-pages.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

.github/workflows/pages.yml

Lines changed: 0 additions & 50 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,54 @@ jobs:
1313
- name: Run tests
1414
run: |
1515
./test.sh
16-
test_windows:
17-
name: Windows build and tests
18-
runs-on: windows-latest
19-
steps:
20-
- name: Checkout source code
21-
uses: actions/checkout@v2
16+
# test_windows:
17+
# name: Windows build and tests
18+
# runs-on: windows-latest
19+
# steps:
20+
# - name: Checkout source code
21+
# uses: actions/checkout@v2
2222

23-
- name: Add msbuild to PATH
24-
uses: microsoft/setup-msbuild@v1
23+
# - name: Add msbuild to PATH
24+
# uses: microsoft/setup-msbuild@v1
2525

26-
- name: Install dependencies
27-
run: |
28-
Invoke-WebRequest -URI https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable-msvc.zip -OutFile libsodium-1.0.18-stable-msvc.zip
29-
tar -xf libsodium-1.0.18-stable-msvc.zip
30-
rm libsodium-1.0.18-stable-msvc.zip
31-
cp .\libsodium\x64\Release\v143\dynamic\libsodium.dll $env:PGROOT\lib
32-
Invoke-WebRequest -URI https://github.com/theory/pgtap/archive/refs/tags/v1.2.0.zip -OutFile pgtap.zip
33-
tar -xf pgtap.zip
34-
rm pgtap.zip
35-
cd pgtap-1.2.0
36-
cp .\sql\pgtap.sql.in .\sql\pgtap.sql
37-
perl.exe '-pi.bak' -e "s/TAPSCHEMA/tap/g" .\sql\pgtap.sql
38-
perl.exe '-pi.bak' -e "s/__OS__/win32/g" .\sql\pgtap.sql
39-
perl.exe '-pi.bak' -e "s/__VERSION__/0.24/g" .\sql\pgtap.sql
40-
perl.exe '-pi.bak' -e "s/^-- ## //g" .\sql\pgtap.sql
41-
cp .\sql\pgtap.sql $env:PGROOT\share\extension
42-
cp .\pgtap.control $env:PGROOT\share\extension
43-
cp .\contrib\pgtap.spec $env:PGROOT\share\contrib
44-
ren $env:PGROOT\share\extension\pgtap.sql $env:PGROOT\share\extension\pgtap--1.2.0.sql
45-
shell: pwsh
26+
# - name: Install dependencies
27+
# run: |
28+
# Invoke-WebRequest -URI https://download.libsodium.org/libsodium/releases/libsodium-1.0.18-stable-msvc.zip -OutFile libsodium-1.0.18-stable-msvc.zip
29+
# tar -xf libsodium-1.0.18-stable-msvc.zip
30+
# rm libsodium-1.0.18-stable-msvc.zip
31+
# cp .\libsodium\x64\Release\v143\dynamic\libsodium.dll $env:PGROOT\lib
32+
# Invoke-WebRequest -URI https://github.com/theory/pgtap/archive/refs/tags/v1.2.0.zip -OutFile pgtap.zip
33+
# tar -xf pgtap.zip
34+
# rm pgtap.zip
35+
# cd pgtap-1.2.0
36+
# cp .\sql\pgtap.sql.in .\sql\pgtap.sql
37+
# perl.exe '-pi.bak' -e "s/TAPSCHEMA/tap/g" .\sql\pgtap.sql
38+
# perl.exe '-pi.bak' -e "s/__OS__/win32/g" .\sql\pgtap.sql
39+
# perl.exe '-pi.bak' -e "s/__VERSION__/0.24/g" .\sql\pgtap.sql
40+
# perl.exe '-pi.bak' -e "s/^-- ## //g" .\sql\pgtap.sql
41+
# cp .\sql\pgtap.sql $env:PGROOT\share\extension
42+
# cp .\pgtap.control $env:PGROOT\share\extension
43+
# cp .\contrib\pgtap.spec $env:PGROOT\share\contrib
44+
# ren $env:PGROOT\share\extension\pgtap.sql $env:PGROOT\share\extension\pgtap--1.2.0.sql
45+
# shell: pwsh
4646

47-
- name: Run msbuild
48-
working-directory: ./build
49-
run: |
50-
msbuild pgsodium.vcxproj /p:libsodiumLocation=..\libsodium /p:PostgreSQLLocation=%PGROOT% /p:Configuration=Release /p:Platform=x64 /p:platformToolset=v143
47+
# - name: Run msbuild
48+
# working-directory: ./build
49+
# run: |
50+
# msbuild pgsodium.vcxproj /p:libsodiumLocation=..\libsodium /p:PostgreSQLLocation=%PGROOT% /p:Configuration=Release /p:Platform=x64 /p:platformToolset=v143
5151

52-
- name: Install pgsodium, update config, and restart
53-
run: |
54-
cp .\build\x64\Release\pgsodium.dll $env:PGROOT\lib
55-
cp pgsodium.control $env:PGROOT\share\extension
56-
cp .\sql\* $env:PGROOT\share\extension
57-
cp .\getkey_scripts\pgsodium_getkey.bat $env:PGDATA\
58-
((Get-Content -Path $env:PGDATA\postgresql.conf) -Replace "#shared_preload_libraries = ''","shared_preload_libraries = 'pgsodium'") | Set-Content -Path $env:PGDATA\postgresql.conf
59-
Add-Content -Path $env:PGDATA\postgresql.conf -Value ("pgsodium.getkey_script = '$env:PGDATA\pgsodium_getkey.bat'" -Replace "\\","/")
60-
& $env:PGBIN\pg_ctl restart -D $env:PGDATA
61-
shell: pwsh
52+
# - name: Install pgsodium, update config, and restart
53+
# run: |
54+
# cp .\build\x64\Release\pgsodium.dll $env:PGROOT\lib
55+
# cp pgsodium.control $env:PGROOT\share\extension
56+
# cp .\sql\* $env:PGROOT\share\extension
57+
# cp .\getkey_scripts\pgsodium_getkey.bat $env:PGDATA\
58+
# ((Get-Content -Path $env:PGDATA\postgresql.conf) -Replace "#shared_preload_libraries = ''","shared_preload_libraries = 'pgsodium'") | Set-Content -Path $env:PGDATA\postgresql.conf
59+
# Add-Content -Path $env:PGDATA\postgresql.conf -Value ("pgsodium.getkey_script = '$env:PGDATA\pgsodium_getkey.bat'" -Replace "\\","/")
60+
# & $env:PGBIN\pg_ctl restart -D $env:PGDATA
61+
# shell: pwsh
6262

63-
- name: Run pgsodium tests
64-
run: |
65-
& $env:PGBIN\psql -q -U postgres -f .\test\test.sql
66-
shell: pwsh
63+
# - name: Run pgsodium tests
64+
# run: |
65+
# & $env:PGBIN\psql -q -U postgres -f .\test\test.sql
66+
# shell: pwsh

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ ARG DEBIAN_FRONTEND=noninteractive
55
# install base dependences
66
RUN apt-get update && \
77
apt-get install -y make cmake git curl build-essential m4 sudo gdbserver \
8-
gdb libreadline-dev bison flex zlib1g-dev tmux zile zip vim gawk wget libicu-dev pkg-config
8+
gdb libreadline-dev bison flex zlib1g-dev tmux zile zip vim gawk wget libicu-dev pkg-config \
9+
python3 python3-pip python3-venv
910

1011
# add postgres user and make data dir
1112
RUN groupadd -r postgres && useradd --no-log-init -r -m -s /bin/bash -g postgres -G sudo postgres

docs/aead.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# AEAD

docs/box.md

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
# Public Key Cryptography
2+
3+
4+
The `box` API uses public key encryption
5+
to securely send messages between two parties who only know each
6+
others public keys. Each party has a secret key that is used to
7+
encrypt messages.
8+
9+
[Libsodium Documentation](https://doc.libsodium.org/public-key_cryptography/authenticated_encryption)
10+
11+
`crypto_box_new_keypair()` returns a new, randomly generated, pair of
12+
keys for public key encryption. The public key can be shared with
13+
anyone. The secret key must never be shared.
14+
15+
`crypto_box_noncegen()` generates a random nonce which will be used
16+
when encrypting messages. For security, each nonce must be used only
17+
once, though it is not a secret. The purpose of the nonce is to add
18+
randomness to the message so that the same message encrypted multiple
19+
times with the same key will produce different ciphertexts.
20+
21+
`crypto_box()` encrypts a message using a nonce, the intended
22+
recipient's public key and the sender's secret key. The resulting
23+
ciphertext can only be decrypted by the intended recipient using their
24+
secret key. The nonce must be sent along with the ciphertext.
25+
26+
`crypto_box_open()` descrypts a ciphertext encrypted using
27+
`crypto_box()`. It takes the ciphertext, nonce, the sender's public
28+
key and the recipient's secret key as parameters, and returns the
29+
original message. Note that the recipient should ensure that the
30+
public key belongs to the sender.
31+
32+
33+
Public key encryption requires each party have a pair of keys, one
34+
public and one private, and a nonce. The nonce doesn't have to be
35+
confidential, but it should never ever be reused with the same
36+
key. The easiest way to generate a nonce is to use
37+
`crypto_box_noncegen`:
38+
``` postgres-console
39+
select crypto_box_new_seed() seed \gset
40+
SELECT pgsodium.crypto_box_noncegen() nonce \gset
41+
```
42+
Now create a new keypair for both bob and alice.
43+
``` postgres-console
44+
SELECT public, secret FROM crypto_box_new_keypair() \gset bob_
45+
SELECT public, secret FROM crypto_box_seed_new_keypair(:'seed') \gset alice_
46+
SELECT pgsodium.crypto_box('hello bob', :'nonce', :'bob_public', :'alice_secret') atob \gset
47+
SELECT :'atob';
48+
┌──────────────────────────────────────────────────────┐
49+
│ ?column? │
50+
├──────────────────────────────────────────────────────┤
51+
│ \x7fdd158c74cc98a57abcc69eaf2c83e48e3e46150a018b2e4e │
52+
└──────────────────────────────────────────────────────┘
53+
(1 row)
54+
55+
select pgsodium.crypto_box_open(:'atob', :'nonce', :'alice_public', :'bob_secret');
56+
┌──────────────────────┐
57+
│ crypto_box_open │
58+
├──────────────────────┤
59+
│ \x68656c6c6f20626f62 │
60+
└──────────────────────┘
61+
(1 row)
62+
63+
```
64+
Sealed boxes are designed to anonymously send messages to a recipient
65+
given its public key.
66+
67+
Only the recipient can decrypt these messages, using its private
68+
key. While the recipient can verify the integrity of the message, it
69+
cannot verify the identity of the sender.
70+
71+
A message is encrypted using an ephemeral key pair, whose secret part
72+
is destroyed right after the encryption process.
73+
74+
Without knowing the secret key used for a given message, the sender
75+
cannot decrypt its own message later. And without additional data, a
76+
message cannot be correlated with the identity of its sender.
77+
``` postgres-console
78+
SELECT pgsodium.crypto_box_seal('bob is your uncle', :'bob_public') sealed \gset
79+
SELECT pgsodium.crypto_box_seal_open(:'sealed', :'bob_public', :'bob_secret');
80+
┌──────────────────────────────────────┐
81+
│ crypto_box_seal_open │
82+
├──────────────────────────────────────┤
83+
│ \x626f6220697320796f757220756e636c65 │
84+
└──────────────────────────────────────┘
85+
(1 row)
86+
87+
```

docs/derive.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Key Derivation
2+
3+
Multiple secret subkeys can be derived from a single master key.
4+
5+
Given the master key and a key identifier, a subkey can be
6+
deterministically computed. However, given a subkey, an attacker
7+
cannot compute the master key nor any other subkeys.
8+
9+
The crypto_kdf API can derive up to 2^64 keys from a single master key
10+
and context, and individual subkeys can have an arbitrary length
11+
between 128 (16 bytes) and 512 bits (64 bytes).
12+
``` postgres-console
13+
select pgsodium.derive_key(42);
14+
┌────────────────────────────────────────────────────────────────────┐
15+
│ derive_key │
16+
├────────────────────────────────────────────────────────────────────┤
17+
│ \xedb9dad4a157825d64966a45baab5050d8a443084dc2c0b738016eda4a3fabea │
18+
└────────────────────────────────────────────────────────────────────┘
19+
(1 row)
20+
21+
select pgsodium.derive_key(42, 64, 'foozbarz');
22+
┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
23+
│ derive_key │
24+
├────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
25+
│ \xba70d8f39bb7803a1b89e14d949f545ea1a0cc03357368f38c57cfe61b61ecfddfe15957bffb9ded0c85cf0b0a0714f69413cb297c59cb4e4e9d0a55e9032aa0 │
26+
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
27+
(1 row)
28+
29+
```

0 commit comments

Comments
 (0)