99
1010LOCATION_PREFIX = "@"
1111DEFAULT_LOCATION = "https://oydid.ownyourdata.eu"
12- VERSION = "0.5.8 "
12+ VERSION = "0.6.1 "
1313LOG_HASH_OPTIONS = { :digest => "sha2-256" , :encode => "base58btc" }
1414
1515# internal functions -------------------------------
@@ -515,6 +515,7 @@ def print_help()
515515 puts " log - print relevant log for given DID or log entry hash"
516516 puts " logs - print all available log entries for given DID or log hash"
517517 puts " pubkeys - list all authorized public keys for specified DID"
518+ puts " sign - sign payload with provided private key"
518519 puts " toW3C - read OYDID internal document and convert to W3C-conform"
519520 puts " DID document"
520521 # puts " challenge - publish challenge for given DID and revoke specified as"
@@ -525,6 +526,9 @@ def print_help()
525526 puts " jws - output signed DIDComm message, reads from STDIN"
526527 puts " jws-verify - read JWS and verify signature"
527528 puts ""
529+ puts " -- JWK handling --"
530+ puts " jwks - create JSON Web Key Set"
531+ puts ""
528532 puts "Semantic Container operations:"
529533 puts " auth - retrieve OAuth2 bearer token using DID Auth"
530534 puts " sc_init - create initial DID for a Semantic Container "
@@ -762,12 +766,12 @@ def print_help()
762766
763767case operation . to_s
764768# JSON input
765- when "create" , "confirm" ,
769+ when "create" , "confirm" ,
766770 "fromW3C" , "toW3C" ,
767771 "message" , "jws" , "encrypt-message" , "sign-message" ,
768772 "vc" , "vc-proof" , "vc-push" , "vc-verify" ,
769773 "vp" , "vp-push" , "vp-verify" ,
770- "dri" , "encrypt"
774+ "dri" , "encrypt" , "jwks" , "jwk2mb"
771775 input_content = [ ]
772776 ARGF . each_line { |line | input_content << line }
773777 content = JSON . parse ( input_content . join ( "" ) ) rescue nil
@@ -812,8 +816,8 @@ def print_help()
812816 exit ( -1 )
813817 end
814818 end
815- # JWT input
816- when "decrypt-jwt" , "verify-jws" , "verify-signed-message" , "decrypt"
819+ # JWT/raw input
820+ when "decrypt-jwt" , "verify-jws" , "verify-signed-message" , "decrypt" , "sign"
817821 content = [ ]
818822 ARGF . each_line { |line | content << line }
819823 content = content . join ( '' ) . strip
@@ -1158,6 +1162,41 @@ def print_help()
11581162 end
11591163 end
11601164 end
1165+ when "sign"
1166+ # checks---
1167+ # require --doc-enc
1168+ if options [ :doc_enc ] . to_s == ''
1169+ if options [ :silent ] . nil? || !options [ :silent ]
1170+ if options [ :json ] . nil? || !options [ :json ]
1171+ puts "Error: require private key provided as --doc-enc"
1172+ else
1173+ puts '{"error": "require private key provided as --doc-enc"}'
1174+ end
1175+ end
1176+ exit ( -1 )
1177+ end
1178+ retVal , msg = Oydid . sign ( content , options [ :doc_enc ] . to_s )
1179+ if retVal . nil?
1180+ if msg . to_s != ""
1181+ if options [ :silent ] . nil? || !options [ :silent ]
1182+ if options [ :json ] . nil? || !options [ :json ]
1183+ puts "Error: " + msg . to_s
1184+ else
1185+ puts '{"error": "' + msg + '"}'
1186+ end
1187+ end
1188+ end
1189+ exit ( -1 )
1190+ else
1191+ if options [ :silent ] . nil? || !options [ :silent ]
1192+ if options [ :json ] . nil? || !options [ :json ]
1193+ puts "Signature: " + retVal . to_s
1194+ else
1195+ puts "{\" sig\" : \" #{ retVal . to_s } \" }"
1196+ end
1197+ end
1198+ end
1199+
11611200when "pubkeys"
11621201 retVal , msg = Oydid . getDelegatedPubKeysFromDID ( input_did , options [ :pubkey_type ] )
11631202 if retVal . nil?
@@ -1696,6 +1735,17 @@ def print_help()
16961735 end
16971736 end
16981737
1738+ when "jwks"
1739+ result , msg = Oydid . build_jwks ( content , input_did , options )
1740+ if msg . to_s != ''
1741+ if options [ :json ] . nil? || !options [ :json ]
1742+ puts msg
1743+ else
1744+ puts { "error" => msg } . to_json
1745+ end
1746+ end
1747+ puts result
1748+
16991749# internal helper
17001750when "dri"
17011751 result = Oydid . hash ( Oydid . canonical ( content . to_json ) )
@@ -1714,6 +1764,22 @@ def print_help()
17141764 puts "private key: " + privateKey . to_s
17151765 puts "signing public key: " + signgingPublicKey . to_s
17161766 puts "encryption public key: " + encryptionPublicKey . to_s
1767+ when "jwk2mb"
1768+ privateKey , msg = Oydid . private_key_from_jwk ( content , options )
1769+ if msg . to_s != '' || privateKey . nil?
1770+ if options [ :json ] . nil? || !options [ :json ]
1771+ puts msg
1772+ else
1773+ puts { "error" => msg } . to_json
1774+ end
1775+ else
1776+ if options [ :json ] . nil? || !options [ :json ]
1777+ puts "private key: " + privateKey . to_s
1778+ else
1779+ puts '{"private_key": "' + privateKey . to_s + '"}'
1780+ end
1781+ end
1782+
17171783when "encrypt"
17181784 key_type = options [ :key_type ]
17191785 if input_did . to_s != ''
0 commit comments