oydid 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/oydid/basic.rb +65 -3
- data/lib/oydid/didcomm.rb +19 -0
- data/lib/oydid/log.rb +1 -0
- data/lib/oydid.rb +5 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56c65853f4983bcb8214a4027986839c0503adcc1133933f817d8401d8881be7
|
4
|
+
data.tar.gz: 2a6048ab2023f8641e83e7b0162a8c15ef6bdb2c0855d70cef8d6c015ca34720
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 799e94f77486d60beb09c8b8f5101ac5789eb1d000052a1aa396121acbd13e0a935cb06fe0c1849ef4deb75b407da049d1111bd15f0d49bd2863671419da4480
|
7
|
+
data.tar.gz: d513c74e0b307a74a9c7fced1bd3ce5bdaef1941290a70aef447a183e3e31da5c44582d25969cd401ec25379412fb7850d55e5e547972e87ee39e4297e79866c
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.4.
|
1
|
+
0.4.4
|
data/lib/oydid/basic.rb
CHANGED
@@ -25,6 +25,11 @@ class Oydid
|
|
25
25
|
message.to_json_c14n
|
26
26
|
end
|
27
27
|
|
28
|
+
def self.percent_encode(did)
|
29
|
+
# remove "https://" from string as it is default
|
30
|
+
did = did.sub("https://","").sub("@", "%40").sub("http://","http%3A%2F%2F")
|
31
|
+
end
|
32
|
+
|
28
33
|
# key management ----------------------------
|
29
34
|
def self.generate_private_key(input, method = "ed25519-priv")
|
30
35
|
begin
|
@@ -47,13 +52,21 @@ class Oydid
|
|
47
52
|
return [encode([omc, length, raw_key].pack("SCa#{length}")), ""]
|
48
53
|
end
|
49
54
|
|
50
|
-
def self.public_key(private_key)
|
55
|
+
def self.public_key(private_key, method = "ed25519-pub")
|
51
56
|
code, length, digest = decode(private_key).unpack('SCa*')
|
52
57
|
case Multicodecs[code].name
|
53
58
|
when 'ed25519-priv'
|
54
|
-
|
59
|
+
case method
|
60
|
+
when 'ed25519-pub'
|
61
|
+
public_key = Ed25519::SigningKey.new(digest).verify_key
|
62
|
+
when 'x25519-pub'
|
63
|
+
public_key = RbNaCl::PrivateKey.new(digest).public_key
|
64
|
+
else
|
65
|
+
return [nil, "unsupported key codec"]
|
66
|
+
end
|
55
67
|
length = public_key.to_bytes.bytesize
|
56
|
-
return [encode([Multicodecs[
|
68
|
+
return [encode([Multicodecs[method].code, length, public_key].pack("CCa#{length}")), ""]
|
69
|
+
|
57
70
|
else
|
58
71
|
return [nil, "unsupported key codec"]
|
59
72
|
end
|
@@ -91,6 +104,53 @@ class Oydid
|
|
91
104
|
end
|
92
105
|
end
|
93
106
|
|
107
|
+
def self.encrypt(message, public_key)
|
108
|
+
begin
|
109
|
+
code, length, digest = decode(public_key).unpack('CCa*')
|
110
|
+
case Multicodecs[code].name
|
111
|
+
when 'x25519-pub'
|
112
|
+
pubKey = RbNaCl::PublicKey.new(digest)
|
113
|
+
authHash = RbNaCl::Hash.sha256('auth'.dup.force_encoding('ASCII-8BIT'))
|
114
|
+
authKey = RbNaCl::PrivateKey.new(authHash)
|
115
|
+
box = RbNaCl::Box.new(pubKey, authKey)
|
116
|
+
nonce = RbNaCl::Random.random_bytes(box.nonce_bytes)
|
117
|
+
msg = message.force_encoding('ASCII-8BIT')
|
118
|
+
cipher = box.encrypt(nonce, msg)
|
119
|
+
return [
|
120
|
+
{
|
121
|
+
value: cipher.unpack('H*')[0],
|
122
|
+
nonce: nonce.unpack('H*')[0]
|
123
|
+
}, ""
|
124
|
+
]
|
125
|
+
else
|
126
|
+
return [nil, "unsupported key codec"]
|
127
|
+
end
|
128
|
+
rescue
|
129
|
+
return [nil, "encryption failed"]
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.decrypt(message, private_key)
|
134
|
+
begin
|
135
|
+
cipher = [JSON.parse(message)["value"]].pack('H*')
|
136
|
+
nonce = [JSON.parse(message)["nonce"]].pack('H*')
|
137
|
+
code, length, digest = decode(private_key).unpack('SCa*')
|
138
|
+
case Multicodecs[code].name
|
139
|
+
when 'ed25519-priv'
|
140
|
+
privKey = RbNaCl::PrivateKey.new(digest)
|
141
|
+
authHash = RbNaCl::Hash.sha256('auth'.dup.force_encoding('ASCII-8BIT'))
|
142
|
+
authKey = RbNaCl::PrivateKey.new(authHash).public_key
|
143
|
+
box = RbNaCl::Box.new(authKey, privKey)
|
144
|
+
retVal = box.decrypt(nonce, cipher)
|
145
|
+
return [retVal, ""]
|
146
|
+
else
|
147
|
+
return [nil, "unsupported key codec"]
|
148
|
+
end
|
149
|
+
rescue
|
150
|
+
return [nil, "decryption failed"]
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
94
154
|
def self.read_private_key(filename)
|
95
155
|
begin
|
96
156
|
f = File.open(filename)
|
@@ -157,6 +217,7 @@ class Oydid
|
|
157
217
|
|
158
218
|
case doc_location
|
159
219
|
when /^http/
|
220
|
+
doc_location = doc_location.sub("%3A%2F%2F","://")
|
160
221
|
retVal = HTTParty.get(doc_location + "/doc/" + doc_hash)
|
161
222
|
if retVal.code != 200
|
162
223
|
msg = retVal.parsed_response("error").to_s rescue "invalid response from " + doc_location.to_s + "/doc/" + doc_hash.to_s
|
@@ -190,6 +251,7 @@ class Oydid
|
|
190
251
|
|
191
252
|
case doc_location
|
192
253
|
when /^http/
|
254
|
+
doc_location = doc_location.sub("%3A%2F%2F","://")
|
193
255
|
retVal = HTTParty.get(doc_location + "/doc_raw/" + doc_hash)
|
194
256
|
if retVal.code != 200
|
195
257
|
msg = retVal.parsed_response("error").to_s rescue "invalid response from " + doc_location.to_s + "/doc/" + doc_hash.to_s
|
data/lib/oydid/didcomm.rb
CHANGED
@@ -98,4 +98,23 @@ class Oydid
|
|
98
98
|
return [nil, "verification failed"]
|
99
99
|
end
|
100
100
|
end
|
101
|
+
|
102
|
+
# DID Auth for data container with challenge ---
|
103
|
+
def self.token_from_challenge(host, pwd)
|
104
|
+
sid = SecureRandom.hex(20).to_s
|
105
|
+
retVal = HTTParty.post(host + "/oydid/init",
|
106
|
+
headers: { 'Content-Type' => 'application/json' },
|
107
|
+
body: { "session_id": sid }.to_json )
|
108
|
+
challenge = retVal.parsed_response["challenge"]
|
109
|
+
signed_challenge = Oydid.sign(challenge, Oydid.generate_private_key(pwd).first).first
|
110
|
+
public_key = Oydid.public_key(Oydid.generate_private_key(pwd).first).first
|
111
|
+
retVal = HTTParty.post(host + "/oydid/token",
|
112
|
+
headers: { 'Content-Type' => 'application/json' },
|
113
|
+
body: {
|
114
|
+
"session_id": sid,
|
115
|
+
"signed_challenge": signed_challenge,
|
116
|
+
"public_key": public_key
|
117
|
+
}.to_json)
|
118
|
+
return retVal.parsed_response["access_token"]
|
119
|
+
end
|
101
120
|
end
|
data/lib/oydid/log.rb
CHANGED
data/lib/oydid.rb
CHANGED
@@ -139,6 +139,11 @@ class Oydid
|
|
139
139
|
return write(content, did, "update", options)
|
140
140
|
end
|
141
141
|
|
142
|
+
def self.simulate_did(content, did, mode, options)
|
143
|
+
user_did, didDocument, revoc_log, l1, l2, r1, privateKey, revocationKey, did_old, log_old, msg = Oydid.generate_base(content, did, mode, options)
|
144
|
+
return [user_did, msg]
|
145
|
+
end
|
146
|
+
|
142
147
|
def self.generate_base(content, did, mode, options)
|
143
148
|
# input validation
|
144
149
|
did_doc = JSON.parse(content.to_json) rescue nil
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oydid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Fabianek
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dag
|