cul-handles 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/cul-handles.gemspec +79 -0
- data/lib/cul/handles/base_message.rb +121 -0
- data/lib/cul/handles/base_request.rb +153 -0
- data/lib/cul/handles/base_response.rb +191 -0
- data/lib/cul/handles/challenge_answer_request.rb +46 -0
- data/lib/cul/handles/challenge_response.rb +23 -0
- data/lib/cul/handles/client.rb +113 -0
- data/lib/cul/handles/create_handle_request.rb +22 -0
- data/lib/cul/handles/delete_handle_request.rb +22 -0
- data/lib/cul/handles/delete_value_request.rb +14 -0
- data/lib/cul/handles/handle_value_request.rb +90 -0
- data/lib/cul/handles/hdl.rb +244 -0
- data/lib/cul/handles/modify_value_request.rb +10 -0
- data/lib/cul/handles/resolution_request.rb +31 -0
- data/lib/cul/handles/resolution_response.rb +168 -0
- data/lib/cul/handles/session_request.rb +126 -0
- data/lib/cul/handles/session_setup_response.rb +25 -0
- data/lib/cul/handles/set_value_request.rb +6 -0
- metadata +24 -2
@@ -0,0 +1,168 @@
|
|
1
|
+
module Cul
|
2
|
+
module Handles
|
3
|
+
class ResolutionResponse < BaseResponse
|
4
|
+
def parseBody(data)
|
5
|
+
offset = 0
|
6
|
+
@packet.concat(data)
|
7
|
+
# parse return digest
|
8
|
+
if self.returnRequestDigest()
|
9
|
+
self.digestAlg = data[offset]
|
10
|
+
if (@digestLength)
|
11
|
+
@messageDigest = data[1..(@digestLength)]
|
12
|
+
offset = 1 + @digestLength
|
13
|
+
else
|
14
|
+
@messageDigest = []
|
15
|
+
end
|
16
|
+
end
|
17
|
+
@body = data[offset...@bodyLength]
|
18
|
+
arrayInfo = readByteArray(data,offset)
|
19
|
+
offset = offset + arrayInfo[0]
|
20
|
+
@handle = arrayInfo[1]
|
21
|
+
numVals = fromBytes(data[offset...offset+4])
|
22
|
+
offset = offset + 4
|
23
|
+
@handleValues = []
|
24
|
+
for i in (1..numVals)
|
25
|
+
valLen = calculateValueLen(data,offset)
|
26
|
+
value = HandleValue.new(data[offset...offset+valLen])
|
27
|
+
@handleValues.push(value)
|
28
|
+
puts value
|
29
|
+
offset = offset + valLen
|
30
|
+
end
|
31
|
+
end
|
32
|
+
def handle
|
33
|
+
if(@handle)
|
34
|
+
return @handle.pack('c*')
|
35
|
+
else
|
36
|
+
return ''
|
37
|
+
end
|
38
|
+
end
|
39
|
+
def handleValue(type='URL')
|
40
|
+
@handleValues.each{|value|
|
41
|
+
if value.type == type
|
42
|
+
return value.data
|
43
|
+
end
|
44
|
+
}
|
45
|
+
return nil
|
46
|
+
end
|
47
|
+
end
|
48
|
+
class HandleValue
|
49
|
+
include Hdl
|
50
|
+
PERM_ADMIN_READ = 0x8
|
51
|
+
PERM_ADMIN_WRITE = 0x4
|
52
|
+
PERM_PUBLIC_READ = 0x2
|
53
|
+
PERM_PUBLIC_WRITE = 0x1
|
54
|
+
TTL_TYPE_RELATIVE = 0
|
55
|
+
TTL_TYPE_ABSOLUTE = 1
|
56
|
+
MAX_RECOGNIZED_TTL = 86400*2 # 2 days
|
57
|
+
def initialize(data=[],handle="")
|
58
|
+
super()
|
59
|
+
@handle=handle
|
60
|
+
@refs = []
|
61
|
+
@data = []
|
62
|
+
@type = []
|
63
|
+
@perm = 14 # admin r/w; public r
|
64
|
+
@ttlType = TTL_TYPE_RELATIVE # default
|
65
|
+
@ttl = asBytes(86400) # default is 86400 seconds = 1440 minutes = 24 hours
|
66
|
+
@timestamp = asBytes(Time.new().to_i) # number of seconds since computing era
|
67
|
+
deserialize(data) unless data.length == 0
|
68
|
+
end
|
69
|
+
def deserialize(data)
|
70
|
+
@index = data[0..3]
|
71
|
+
@timestamp = data[4..7]
|
72
|
+
@ttlType = data[8]
|
73
|
+
@ttl = data[9..12]
|
74
|
+
@perm = data[13]
|
75
|
+
typeLen = fromBytes(data[14..17])
|
76
|
+
offset = 18
|
77
|
+
@type = data[18...18+typeLen]
|
78
|
+
offset = offset + typeLen
|
79
|
+
dataLen = fromBytes(data[offset...offset+4])
|
80
|
+
offset = offset + 4
|
81
|
+
@data = data[offset...offset+dataLen]
|
82
|
+
offset = offset + dataLen
|
83
|
+
refsLen = fromBytes(data[offset...offset+4])
|
84
|
+
offset = offset + 4
|
85
|
+
@refs = []
|
86
|
+
(1..refsLen).each{
|
87
|
+
@refs.push(fromBytes(data[offset...offset+4]))
|
88
|
+
offset = offset + 4
|
89
|
+
}
|
90
|
+
end
|
91
|
+
def serialize()
|
92
|
+
result = [].concat(@index)
|
93
|
+
result.concat(@timestamp)
|
94
|
+
result.concat([@ttlType])
|
95
|
+
result.concat(@ttl)
|
96
|
+
result.concat([@perm])
|
97
|
+
result.concat(asBytes(@type.length))
|
98
|
+
result.concat(@type)
|
99
|
+
result.concat(asBytes(@data.length))
|
100
|
+
result.concat(@data)
|
101
|
+
result.concat(asBytes(@refs.length))
|
102
|
+
if(@refs.length > 0)
|
103
|
+
@refs.each{ | ref|
|
104
|
+
result.concat(asBytes(ref))
|
105
|
+
}
|
106
|
+
end
|
107
|
+
return result
|
108
|
+
end
|
109
|
+
def handle
|
110
|
+
@handle
|
111
|
+
end
|
112
|
+
def index=(val)
|
113
|
+
@index= val
|
114
|
+
end
|
115
|
+
def index
|
116
|
+
fromBytes(@index)
|
117
|
+
end
|
118
|
+
def timestamp=(val)
|
119
|
+
@timestamp=val
|
120
|
+
end
|
121
|
+
def ttlType=(val)
|
122
|
+
@ttlType = val
|
123
|
+
end
|
124
|
+
def ttl=(val)
|
125
|
+
@ttl = val
|
126
|
+
end
|
127
|
+
def perm=(val)
|
128
|
+
@perm = val
|
129
|
+
end
|
130
|
+
def adminRead
|
131
|
+
@perm & PERM_ADMIN_READ
|
132
|
+
end
|
133
|
+
def adminWrite
|
134
|
+
@perm & PERM_ADMIN_WRITE
|
135
|
+
end
|
136
|
+
def publicRead
|
137
|
+
@perm & PERM_PUBLIC_READ
|
138
|
+
end
|
139
|
+
def publicWrite
|
140
|
+
@perm & PERM_PUBLIC_WRITE
|
141
|
+
end
|
142
|
+
def type=(val)
|
143
|
+
@type=val
|
144
|
+
end
|
145
|
+
def type
|
146
|
+
return @type.pack('U*')
|
147
|
+
end
|
148
|
+
def data=(val)
|
149
|
+
@data=val
|
150
|
+
end
|
151
|
+
def data
|
152
|
+
@data.pack('U*')
|
153
|
+
end
|
154
|
+
def refs=(val)
|
155
|
+
@refs = val
|
156
|
+
end
|
157
|
+
def to_s
|
158
|
+
if (type == "HS_ADMIN")
|
159
|
+
return "admin handle data: ttl= " + fromBytes(@ttl).to_s + " ; ttlType= " + @ttlType.to_s + "; index = " + index.to_s + "; " + decodeAdminData(@data).to_s + "; permissions = " + @perm.to_s
|
160
|
+
end
|
161
|
+
return "type: " + type + "; index=" + index.to_s + "; data.length: " + @data.length.to_s + " ; data: " + data + "; data(hex): " + @data.collect { |element| "%02x" % element }.join+ "; permissions = " + @perm.to_s
|
162
|
+
end
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
module Cul
|
2
|
+
module Handles
|
3
|
+
class SessionSetupRequest < BaseRequest
|
4
|
+
include Hdl
|
5
|
+
attr_reader :dh
|
6
|
+
KEYMAX = (2**513)-1
|
7
|
+
def initialize(authHandle, authIndex)
|
8
|
+
super()
|
9
|
+
@opCode = asBytes(OC_SESSION_SETUP)
|
10
|
+
@sessionId = [0,0,0,0]
|
11
|
+
@requestId = [0,0,0,0]
|
12
|
+
@siteInfoSerial = [0,0,0,0]
|
13
|
+
self.responseCode = 0
|
14
|
+
self.authoritative=true
|
15
|
+
self.returnRequestDigest=true
|
16
|
+
self.encrypt=false
|
17
|
+
self.publicOnly=false
|
18
|
+
self.certify=true
|
19
|
+
self.cacheCertify=true
|
20
|
+
self.recursive=true
|
21
|
+
self.continuous=false
|
22
|
+
self.keepAlive=false
|
23
|
+
self.expirationTime=0
|
24
|
+
@dh = DH.new(53,5,KEYMAX)
|
25
|
+
while(not @dh.valid?)
|
26
|
+
@dh.generate
|
27
|
+
end
|
28
|
+
self.body= getAttributes(authHandle, authIndex)
|
29
|
+
end
|
30
|
+
def getAttributes(authHandle, authIndex)
|
31
|
+
# identity att
|
32
|
+
identity = toProtocolString("HS_SESSION_IDENTITIY")
|
33
|
+
identity.concat(toProtocolString(authHandle))
|
34
|
+
identity.concat(asBytes(authIndex))
|
35
|
+
# key exchange att
|
36
|
+
exchange = toProtocolString("HS_SESSION_KEY_EXCHANGE")
|
37
|
+
exchange.concat(toProtocolString("DIFFIE_HELLMAN"))
|
38
|
+
exchange.concat(@dh.encodeKeyParms)
|
39
|
+
# timeout att
|
40
|
+
timeout = toProtocolString("HS_SESSION_TIMEOUT")
|
41
|
+
timeout.concat([0,0,0,120])
|
42
|
+
[0,0,0,2].concat(identity).concat(timeout)
|
43
|
+
end
|
44
|
+
def indexList
|
45
|
+
[0,0,0,0]
|
46
|
+
end
|
47
|
+
def typeList
|
48
|
+
[0,0,0,0]
|
49
|
+
end
|
50
|
+
def credentialVersion()
|
51
|
+
return []
|
52
|
+
end
|
53
|
+
def credentialReserved()
|
54
|
+
return []
|
55
|
+
end
|
56
|
+
def credentialOptions()
|
57
|
+
return []
|
58
|
+
end
|
59
|
+
def credentialSigner()
|
60
|
+
return []
|
61
|
+
end
|
62
|
+
def credentialType()
|
63
|
+
return []
|
64
|
+
end
|
65
|
+
def credentialDigestAlg()
|
66
|
+
return []
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
class DH
|
71
|
+
include Hdl
|
72
|
+
attr_reader :prime, :generator, :maxrand, :publickey
|
73
|
+
# def DH.miller_rabin(a, n)
|
74
|
+
#
|
75
|
+
# end
|
76
|
+
# def DH.prime
|
77
|
+
#
|
78
|
+
# end
|
79
|
+
def DH.mod_exp start, e, m
|
80
|
+
result = 1
|
81
|
+
b = start
|
82
|
+
while e > 0
|
83
|
+
result = (result * b) % m if e[0] == 1
|
84
|
+
e = e >> 1
|
85
|
+
b = (b*b) %m
|
86
|
+
end
|
87
|
+
return result
|
88
|
+
end
|
89
|
+
def initialize(prime, generator, maxrand)
|
90
|
+
@prime = prime
|
91
|
+
@generator = generator
|
92
|
+
@maxrand = maxrand
|
93
|
+
@publickey = 0 #public key
|
94
|
+
@key = 0 #shared secret
|
95
|
+
@private = 0 #private key
|
96
|
+
end
|
97
|
+
def generate tries=16 # shared key
|
98
|
+
tries.times do
|
99
|
+
@private = rand(@maxrand)
|
100
|
+
@publickey = DH.mod_exp(@generator, @private, @prime)
|
101
|
+
return @publickey if self.valid?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
def secret f # private key
|
105
|
+
@key = DH.mod_exp(f,@private,@prime)
|
106
|
+
@key
|
107
|
+
end
|
108
|
+
def valid? _e = self.publickey
|
109
|
+
_e and _e.between?(2,self.prime-2) and _e != 0
|
110
|
+
end
|
111
|
+
def encodeKeyParms
|
112
|
+
result = []
|
113
|
+
publicBytes = asBytes(@publickey)
|
114
|
+
result.concat(asBytes(publicBytes.length))
|
115
|
+
result.concat(publicBytes)
|
116
|
+
primeBytes = asBytes(@prime)
|
117
|
+
result.concat(asBytes(primeBytes.length))
|
118
|
+
result.concat(primeBytes)
|
119
|
+
genBytes = asBytes(@generator)
|
120
|
+
result.concat(asBytes(genBytes.length))
|
121
|
+
result.concat(genBytes)
|
122
|
+
result
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Cul
|
2
|
+
module Handles
|
3
|
+
class SessionSetupResponse < BaseResponse
|
4
|
+
attr_reader :serverKey
|
5
|
+
def parseBody(data)
|
6
|
+
puts "parseBody"
|
7
|
+
@digestAlg = data[0]
|
8
|
+
if(@digestAlg == 2)
|
9
|
+
@digest = data[1..20]
|
10
|
+
offset = 21
|
11
|
+
else
|
12
|
+
@digest =data[1..16]
|
13
|
+
offset = 17
|
14
|
+
end
|
15
|
+
keyLen = fromBytes(data[offset...offset+4])
|
16
|
+
offset = offset + 4
|
17
|
+
@serverKey = fromBytes(data[offset...offset+keyLen])
|
18
|
+
@body = []
|
19
|
+
end
|
20
|
+
def to_s
|
21
|
+
super() + "; serverKey: " + @serverKey.to_s
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cul-handles
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Stuart
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-11-
|
12
|
+
date: 2009-11-11 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -38,9 +38,31 @@ files:
|
|
38
38
|
- README.rdoc
|
39
39
|
- Rakefile
|
40
40
|
- VERSION
|
41
|
+
- cul-handles.gemspec
|
41
42
|
- lib/cul-handles.rb
|
43
|
+
- lib/cul/handles/base_message.rb
|
44
|
+
- lib/cul/handles/base_request.rb
|
45
|
+
- lib/cul/handles/base_response.rb
|
46
|
+
- lib/cul/handles/challenge_answer_request.rb
|
47
|
+
- lib/cul/handles/challenge_response.rb
|
48
|
+
- lib/cul/handles/client.rb
|
49
|
+
- lib/cul/handles/create_handle_request.rb
|
50
|
+
- lib/cul/handles/delete_handle_request.rb
|
51
|
+
- lib/cul/handles/delete_value_request.rb
|
52
|
+
- lib/cul/handles/handle_value_request.rb
|
53
|
+
- lib/cul/handles/hdl.rb
|
54
|
+
- lib/cul/handles/modify_value_request.rb
|
55
|
+
- lib/cul/handles/resolution_request.rb
|
56
|
+
- lib/cul/handles/resolution_response.rb
|
57
|
+
- lib/cul/handles/session_request.rb
|
58
|
+
- lib/cul/handles/session_setup_response.rb
|
59
|
+
- lib/cul/handles/set_value_request.rb
|
60
|
+
- test/authn_test.rb
|
42
61
|
- test/cul-handles_test.rb
|
62
|
+
- test/dh_test.rb
|
63
|
+
- test/resolution_test.rb
|
43
64
|
- test/test_helper.rb
|
65
|
+
- test/unsigned_integer_test.rb
|
44
66
|
has_rdoc: true
|
45
67
|
homepage: http://github.com/tastyhat/cul-handles
|
46
68
|
licenses: []
|