This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[docker] reduce image sz with keygen script. (#94)
* add script to generate tessera keys using openssl. * no longer need to install java and tessera in container image. * check if the env has the tessera jar setup, e.g. local dev, and use tessera to generate keys if they do. * image size 1.71GB -> 1.33GB. Co-authored-by: Nicolae Leonte <[email protected]>
- Loading branch information
1 parent
a373597
commit 6d62202
Showing
4 changed files
with
91 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ qubernetes.yaml | |
nodes.yaml | ||
docs | ||
scratch | ||
monitor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#!/usr/bin/env bash | ||
|
||
function usage() { | ||
echo "" | ||
echo "Usage:" | ||
echo " $0 [--keyName fileNamePrefix] [--keepOpenSSLFiles]" | ||
echo "" | ||
echo "Where:" | ||
echo " --keyName specifies the prefix to the generated public(.pub)/private(.key) key files" | ||
echo " --keepOpenSSLFiles doesn't delete the intermediary openssl public/private keys" | ||
echo "" | ||
exit -1 | ||
} | ||
|
||
keepOpenSSLFiles=false | ||
|
||
while (("$#")); do | ||
case "$1" in | ||
--keyName) | ||
keyName=$2 | ||
shift 2 | ||
;; | ||
--keepOpenSSLFiles) | ||
keepOpenSSLFiles=true | ||
shift 1 | ||
;; | ||
--help) | ||
shift | ||
usage | ||
;; | ||
*) | ||
echo "Error: Unsupported command line parameter $1" | ||
usage | ||
;; | ||
esac | ||
done | ||
|
||
if [ "$keyName" == "" ]; then | ||
echo "Error: Please specify a key name prefix." | ||
exit -1 | ||
fi | ||
|
||
#TODO - check whether any files may be overwritten by the script | ||
#TODO - check that all the utilities are available and have the necessary versions | ||
|
||
echo "Key name prefix:" $keyName | ||
echo "keepOpenSSLFiles:" $keepOpenSSLFiles | ||
|
||
openSSLPrivateKeyFile="$keyName-ossl.key" | ||
|
||
openssl genpkey -algorithm x25519 -out $openSSLPrivateKeyFile | ||
|
||
openSSLHexOut="$keyName-ossl.text" | ||
|
||
openssl pkey -in $openSSLPrivateKeyFile -text >$openSSLHexOut | ||
|
||
cat $openSSLHexOut | ||
#sed picks up the relevant lines from the output (6-8 for the public key and 10-12 for the private key) | ||
#tr removes any spaces/:/EOL characters and leaves just the alphanumeric ones | ||
#xxd converts the hex input to binary output | ||
#base64 converts the binary input to based64 encoded output | ||
privateKey=$(sed -n '6,8 p' $openSSLHexOut | tr -cd '[:alnum:]' | xxd -r -p | base64) | ||
publicKey=$(sed -n '10,12 p' $openSSLHexOut | tr -cd '[:alnum:]' | xxd -r -p | base64) | ||
|
||
publicKeyFile="$keyName.pub" | ||
privateKeyFile="$keyName.key" | ||
|
||
#using printf in order to avoid the newline that echo adds | ||
printf "$publicKey" >$publicKeyFile | ||
printf "{\"data\":{\"bytes\":\"$privateKey\"},\"type\":\"unlocked\"}" >$privateKeyFile | ||
|
||
if [ "${keepOpenSSLFiles}" == "false" ]; then | ||
rm $openSSLPrivateKeyFile $openSSLHexOut | ||
fi |