virgil-sdk 4.2.3
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.
- checksums.yaml +7 -0
- data/.DS_Store +0 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/README.md +134 -0
- data/Rakefile +9 -0
- data/bin/console +16 -0
- data/bin/setup +8 -0
- data/dockefiles/Dockerfile-200 +25 -0
- data/dockefiles/Dockerfile-2110 +36 -0
- data/dockefiles/Dockerfile-220 +26 -0
- data/dockefiles/Dockerfile-226 +25 -0
- data/dockefiles/Dockerfile-233 +25 -0
- data/dockefiles/Dockerfile-240 +26 -0
- data/docker-compose.yml +107 -0
- data/lib/virgil/sdk.rb +10 -0
- data/lib/virgil/sdk/client.rb +47 -0
- data/lib/virgil/sdk/client/card.rb +142 -0
- data/lib/virgil/sdk/client/card_validator.rb +104 -0
- data/lib/virgil/sdk/client/http.rb +45 -0
- data/lib/virgil/sdk/client/http/base_connection.rb +112 -0
- data/lib/virgil/sdk/client/http/cards_service_connection.rb +113 -0
- data/lib/virgil/sdk/client/http/request.rb +63 -0
- data/lib/virgil/sdk/client/request_signer.rb +90 -0
- data/lib/virgil/sdk/client/requests.rb +50 -0
- data/lib/virgil/sdk/client/requests/confirm_identity_request.rb +67 -0
- data/lib/virgil/sdk/client/requests/create_card_request.rb +105 -0
- data/lib/virgil/sdk/client/requests/revoke_card_request.rb +85 -0
- data/lib/virgil/sdk/client/requests/signable_request.rb +142 -0
- data/lib/virgil/sdk/client/requests/verify_identity_request.rb +60 -0
- data/lib/virgil/sdk/client/search_criteria.rb +79 -0
- data/lib/virgil/sdk/client/signatures_base64.rb +25 -0
- data/lib/virgil/sdk/client/virgil_client.rb +425 -0
- data/lib/virgil/sdk/cryptography.rb +42 -0
- data/lib/virgil/sdk/cryptography/hashes.rb +44 -0
- data/lib/virgil/sdk/cryptography/hashes/fingerprint.rb +79 -0
- data/lib/virgil/sdk/cryptography/hashes/hash_algorithm.rb +91 -0
- data/lib/virgil/sdk/cryptography/keys.rb +48 -0
- data/lib/virgil/sdk/cryptography/keys/key_pair.rb +46 -0
- data/lib/virgil/sdk/cryptography/keys/key_pair_type.rb +108 -0
- data/lib/virgil/sdk/cryptography/keys/key_storage.rb +177 -0
- data/lib/virgil/sdk/cryptography/keys/private_key.rb +44 -0
- data/lib/virgil/sdk/cryptography/keys/public_key.rb +44 -0
- data/lib/virgil/sdk/cryptography/keys/storage_item.rb +63 -0
- data/lib/virgil/sdk/cryptography/virgil_crypto.rb +411 -0
- data/lib/virgil/sdk/high_level.rb +21 -0
- data/lib/virgil/sdk/high_level/virgil_api.rb +71 -0
- data/lib/virgil/sdk/high_level/virgil_app_credentials.rb +54 -0
- data/lib/virgil/sdk/high_level/virgil_buffer.rb +161 -0
- data/lib/virgil/sdk/high_level/virgil_card.rb +204 -0
- data/lib/virgil/sdk/high_level/virgil_card_manager.rb +294 -0
- data/lib/virgil/sdk/high_level/virgil_card_verifier_info.rb +49 -0
- data/lib/virgil/sdk/high_level/virgil_context.rb +69 -0
- data/lib/virgil/sdk/high_level/virgil_identity.rb +17 -0
- data/lib/virgil/sdk/high_level/virgil_identity/email_confirmation.rb +60 -0
- data/lib/virgil/sdk/high_level/virgil_identity/validation_token.rb +49 -0
- data/lib/virgil/sdk/high_level/virgil_identity/verification_attempt.rb +69 -0
- data/lib/virgil/sdk/high_level/virgil_identity/verification_options.rb +56 -0
- data/lib/virgil/sdk/high_level/virgil_key.rb +168 -0
- data/lib/virgil/sdk/high_level/virgil_key_manager.rb +97 -0
- data/lib/virgil/sdk/version.rb +5 -0
- data/virgil-sdk.gemspec +31 -0
- metadata +203 -0
@@ -0,0 +1,113 @@
|
|
1
|
+
# Copyright (C) 2016 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
35
|
+
module Virgil
|
36
|
+
module SDK
|
37
|
+
module Client
|
38
|
+
module HTTP
|
39
|
+
# Cards service connection class.
|
40
|
+
#
|
41
|
+
# Contains cards service specific errors dictionary.
|
42
|
+
class CardsServiceConnection < BaseConnection
|
43
|
+
ERRORS = {
|
44
|
+
10000 => "Internal application error. You know, shit happens, so do internal server errors.Just take a deep breath and try harder.",
|
45
|
+
20300 => "The Virgil access token was not specified or is invalid",
|
46
|
+
20301 => "The Virgil authenticator service responded with an error",
|
47
|
+
20302 => "The Virgil access token validation has failed on the Virgil Authenticator service",
|
48
|
+
20303 => "The application was not found for the acsses token",
|
49
|
+
20400 => "Request sign is invalid",
|
50
|
+
20401 => "Request sign header is missing",
|
51
|
+
20500 => "The Virgil Card is not available in this application",
|
52
|
+
30000 => "JSON specified as a request is invalid",
|
53
|
+
30010 => "A data inconsistency error",
|
54
|
+
30100 => "Global Virgil Card identity type is invalid, because it can be only an 'email'",
|
55
|
+
30101 => "Virgil Card scope must be either 'global' or 'application'",
|
56
|
+
30102 => "Virgil Card id validation failed",
|
57
|
+
30103 => "Virgil Card data parameter cannot contain more than 16 entries",
|
58
|
+
30104 => "Virgil Card info parameter cannot be empty if specified and must contain 'device' and/or 'device_name' key",
|
59
|
+
30105 => "Virgil Card info parameters length validation failed.The length cannot exceed 256 characters",
|
60
|
+
30106 => "Virgil Card data parameter must be an associative array(https://en.wikipedia.org/wiki/Associative_array)",
|
61
|
+
30107 => "A CSR parameter (content_snapshot) parameter is missing or is incorrect",
|
62
|
+
30111 => "Virgil Card identities passed to search endpoint must be a list of non-empty strings",
|
63
|
+
30113 => "Virgil Card identity type is invalid",
|
64
|
+
30116 => "Virgil Card identity application is invalid",
|
65
|
+
30117 => "Public key length is invalid.It goes from 16 to 2048 bytes",
|
66
|
+
30118 => "Public key must be base64-encoded string",
|
67
|
+
30119 => "Virgil Card data parameter must be a key/value list of strings",
|
68
|
+
30120 => "Virgil Card data parameters must be strings",
|
69
|
+
30121 => "Virgil Card custom data entry value length validation failed.It mustn't exceed 256 characters",
|
70
|
+
30122 => "VirgilIdentity validation token is invalid",
|
71
|
+
30123 => "SCR signs list parameter is missing or is invalid",
|
72
|
+
# 30126 => "SCR sign item signer card id is irrelevant and doesn't match Virgil Card id or Application Id",
|
73
|
+
# 30127 => "SCR sign item signed digest is invalid for the Virgil Card public key",
|
74
|
+
30128 => "SCR sign item signed digest is invalid for the application",
|
75
|
+
30131 => "Virgil Card id specified in the request body must match with the one passed in the URL",
|
76
|
+
30134 => "Virgil Card data parameters key must be aplphanumerical",
|
77
|
+
# 30135 => "Virgil Card validation token must be an object with value parameter",
|
78
|
+
# 30136 => "SCR sign item signed digest is invalid for the virgil identity service",
|
79
|
+
30137 => "Global Virigl Card cannot be created unconfirmed(which means that Virgil VirgilIdentity service sign is mandatory)",
|
80
|
+
30138 => "Virigl Card with the same fingerprint exists already",
|
81
|
+
30139 => "Virigl Card revocation reason isn't specified or is invalid",
|
82
|
+
30140 => "SCR sign validation failed",
|
83
|
+
30141 => "SCR one of signers Virgil Cards is not found",
|
84
|
+
30142 => "SCR sign item is invalid or missing for the Client",
|
85
|
+
30143 => "SCR sign item is invalid or missing for the Virgil Registration Authority service",
|
86
|
+
30300 => "Development Portal sign was not found inside the meta.signs property",
|
87
|
+
30301 => "Development Portal sign is invalid",
|
88
|
+
30302 => "VirgilIdentity Validation Token is invalid or has expired",
|
89
|
+
30303 => "Provided Virgil Card was not found or invalid",
|
90
|
+
40000 => "JSON specified as a request body is invalid",
|
91
|
+
40100 => "VirgilIdentity type is invalid",
|
92
|
+
40110 => "VirgilIdentity's ttl is invalid",
|
93
|
+
40120 => "VirgilIdentity's ctl is invalid",
|
94
|
+
40130 => "VirgilIdentity's token parameter is missing",
|
95
|
+
40140 => "VirgilIdentity's token doesn't match parameters",
|
96
|
+
40150 => "VirgilIdentity's token has expired",
|
97
|
+
40160 => "VirgilIdentity's token cannot be decrypted",
|
98
|
+
40170 => "VirgilIdentity's token parameter is invalid",
|
99
|
+
40180 => "VirgilIdentity is not unconfirmed",
|
100
|
+
40190 => "Hash to be signed parameter is invalid",
|
101
|
+
40200 => "Email identity value validation failed",
|
102
|
+
40210 => "VirgilIdentity's confirmation code is invalid",
|
103
|
+
40300 => "Application value is invalid",
|
104
|
+
40310 => "Application's signed message is invalid",
|
105
|
+
41000 => "VirgilIdentity entity was not found",
|
106
|
+
41010 => "VirgilIdentity's confirmation period has expired",
|
107
|
+
50010 => "Requested route was not found"
|
108
|
+
}
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# Copyright (C) 2016 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
35
|
+
module Virgil
|
36
|
+
module SDK
|
37
|
+
module Client
|
38
|
+
module HTTP
|
39
|
+
# Http request wrapper.
|
40
|
+
#
|
41
|
+
# Attributes:
|
42
|
+
# endpoint: request endpoint
|
43
|
+
# body: request body
|
44
|
+
# headers: dict of request additional headers
|
45
|
+
# method: http request method
|
46
|
+
Request = Struct.new(:endpoint, :body, :headers, :method) do
|
47
|
+
# Constructs new Request object.
|
48
|
+
def initialize(attributes)
|
49
|
+
self.endpoint = attributes[:endpoint]
|
50
|
+
self.body = attributes[:body]
|
51
|
+
self.headers = attributes[:headers]
|
52
|
+
self.method = attributes[:method]
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
Request::GET = :get
|
57
|
+
Request::POST = :post
|
58
|
+
Request::PUT = :put
|
59
|
+
Request::DELETE = :delete
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# Copyright (C) 2016 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
35
|
+
module Virgil
|
36
|
+
module SDK
|
37
|
+
module Client
|
38
|
+
# Class used for signing high_level requests.
|
39
|
+
class RequestSigner
|
40
|
+
attr_reader :crypto
|
41
|
+
|
42
|
+
# Constructs new RequestSigner object
|
43
|
+
def initialize(crypto)
|
44
|
+
@crypto = crypto
|
45
|
+
end
|
46
|
+
|
47
|
+
# Sign passed request with private key.
|
48
|
+
#
|
49
|
+
# Args:
|
50
|
+
# signable_request: request for signing.
|
51
|
+
# private_key: private key to sign with.
|
52
|
+
def self_sign(signable_request, private_key)
|
53
|
+
fingerprint = self.crypto.calculate_fingerprint(
|
54
|
+
signable_request.snapshot
|
55
|
+
)
|
56
|
+
signature = self.crypto.sign(
|
57
|
+
fingerprint.value,
|
58
|
+
private_key
|
59
|
+
)
|
60
|
+
|
61
|
+
signable_request.sign_with(
|
62
|
+
fingerprint.to_hex,
|
63
|
+
signature
|
64
|
+
)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Sign passed request with authority private key.
|
68
|
+
#
|
69
|
+
# Args:
|
70
|
+
# signable_request: request for signing.
|
71
|
+
# signer_id: authority id.
|
72
|
+
# private_key: authority private key to sign with.
|
73
|
+
def authority_sign(signable_request, signer_id, private_key)
|
74
|
+
fingerprint = self.crypto.calculate_fingerprint(
|
75
|
+
signable_request.snapshot
|
76
|
+
)
|
77
|
+
signature = self.crypto.sign(
|
78
|
+
fingerprint.value,
|
79
|
+
private_key
|
80
|
+
)
|
81
|
+
|
82
|
+
signable_request.sign_with(
|
83
|
+
signer_id,
|
84
|
+
signature
|
85
|
+
)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# Copyright (C) 2016 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, bytes, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
module Virgil
|
35
|
+
module SDK
|
36
|
+
module Client
|
37
|
+
module Requests
|
38
|
+
autoload :SignableRequest, 'virgil/sdk/client/requests/signable_request'
|
39
|
+
autoload :RevokeCardRequest,
|
40
|
+
'virgil/sdk/client/requests/revoke_card_request'
|
41
|
+
autoload :CreateCardRequest,
|
42
|
+
'virgil/sdk/client/requests/create_card_request'
|
43
|
+
autoload :VerifyIdentityRequest,
|
44
|
+
'virgil/sdk/client/requests/verify_identity_request'
|
45
|
+
autoload :ConfirmIdentityRequest,
|
46
|
+
'virgil/sdk/client/requests/confirm_identity_request'
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# Copyright (C) 2016 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
35
|
+
|
36
|
+
module Virgil
|
37
|
+
module SDK
|
38
|
+
module Client
|
39
|
+
module Requests
|
40
|
+
class ConfirmIdentityRequest
|
41
|
+
attr_reader :confirmation_code, :action_id, :time_to_live, :count_to_live
|
42
|
+
#
|
43
|
+
def initialize(confirmation_code, action_id, time_to_live, count_to_live)
|
44
|
+
@confirmation_code = confirmation_code
|
45
|
+
@action_id = action_id
|
46
|
+
@time_to_live = time_to_live
|
47
|
+
@count_to_live = count_to_live
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
# # Request model used for json representation.
|
52
|
+
def request_model
|
53
|
+
return {
|
54
|
+
'confirmation_code': confirmation_code,
|
55
|
+
'action_id': action_id,
|
56
|
+
'token': {
|
57
|
+
'time_to_live': time_to_live,
|
58
|
+
'count_to_live': count_to_live
|
59
|
+
}
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# Copyright (C) 2016 Virgil Security Inc.
|
2
|
+
#
|
3
|
+
# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com>
|
4
|
+
#
|
5
|
+
# All rights reserved.
|
6
|
+
#
|
7
|
+
# Redistribution and use in source and binary forms, with or without
|
8
|
+
# modification, are permitted provided that the following conditions are
|
9
|
+
# met:
|
10
|
+
#
|
11
|
+
# (1) Redistributions of source code must retain the above copyright
|
12
|
+
# notice, this list of conditions and the following disclaimer.
|
13
|
+
#
|
14
|
+
# (2) Redistributions in binary form must reproduce the above copyright
|
15
|
+
# notice, this list of conditions and the following disclaimer in
|
16
|
+
# the documentation and/or other materials provided with the
|
17
|
+
# distribution.
|
18
|
+
#
|
19
|
+
# (3) Neither the name of the copyright holder nor the names of its
|
20
|
+
# contributors may be used to endorse or promote products derived from
|
21
|
+
# this software without specific prior written permission.
|
22
|
+
#
|
23
|
+
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR
|
24
|
+
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
25
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
26
|
+
# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
27
|
+
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
28
|
+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
29
|
+
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
30
|
+
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
31
|
+
# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
32
|
+
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
33
|
+
# POSSIBILITY OF SUCH DAMAGE.
|
34
|
+
|
35
|
+
module Virgil
|
36
|
+
module SDK
|
37
|
+
module Client
|
38
|
+
module Requests
|
39
|
+
# Create card signable API request.
|
40
|
+
class CreateCardRequest < SignableRequest
|
41
|
+
attr_accessor :identity, :identity_type, :public_key, :data, :info, :scope
|
42
|
+
|
43
|
+
# Constructs new CreateCardRequest object
|
44
|
+
def initialize(attributes)
|
45
|
+
super()
|
46
|
+
self.identity = attributes[:identity]
|
47
|
+
self.identity_type = attributes[:identity_type]
|
48
|
+
self.public_key = attributes[:raw_public_key]
|
49
|
+
self.scope = attributes[:scope] || Card::APPLICATION
|
50
|
+
self.data = attributes[:data]
|
51
|
+
self.info = attributes[:info]
|
52
|
+
end
|
53
|
+
|
54
|
+
# Restores request from snapshot model.
|
55
|
+
#
|
56
|
+
# Args:
|
57
|
+
# snapshot_model: snapshot model dict
|
58
|
+
def restore_from_snapshot_model(snapshot_model)
|
59
|
+
self.identity = snapshot_model['identity']
|
60
|
+
self.identity_type = snapshot_model['identity_type']
|
61
|
+
self.public_key = snapshot_model['public_key']
|
62
|
+
self.scope = snapshot_model['scope']
|
63
|
+
self.data = snapshot_model.fetch('data', {})
|
64
|
+
self.info = snapshot_model['info']
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
def self.import(data_base64)
|
69
|
+
request = new({})
|
70
|
+
begin
|
71
|
+
request_model = JSON.parse(Base64.decode64(data_base64))
|
72
|
+
rescue JSON::ParserError => e
|
73
|
+
raise ArgumentError.new("data_base64 is not valid")
|
74
|
+
end
|
75
|
+
validation_token = nil
|
76
|
+
if request_model['meta']['validation'] && request_model['meta']['validation']['token']
|
77
|
+
validation_token = Virgil::Crypto::Bytes.from_base64(request_model['meta']['validation']['token'])
|
78
|
+
end
|
79
|
+
request.restore(Virgil::Crypto::Bytes.from_base64(request_model['content_snapshot']),
|
80
|
+
request_model['meta']['signs'],
|
81
|
+
validation_token
|
82
|
+
)
|
83
|
+
request
|
84
|
+
end
|
85
|
+
|
86
|
+
# Constructs snapshot model for exporting and signing.
|
87
|
+
#
|
88
|
+
# Returns:
|
89
|
+
# Dict containing snapshot data model used for card creation request.
|
90
|
+
def snapshot_model
|
91
|
+
model = {
|
92
|
+
'identity': identity,
|
93
|
+
'identity_type': identity_type,
|
94
|
+
'public_key': Virgil::Crypto::Bytes.new(public_key).to_base64,
|
95
|
+
'scope': scope,
|
96
|
+
'data': data
|
97
|
+
}
|
98
|
+
model['info'] = info if (info && info.any?)
|
99
|
+
model
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|