Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
key-storage-agent
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Code
key-storage-agent
Commits
5629985f
Commit
5629985f
authored
6 years ago
by
Viktor Popov
Browse files
Options
Downloads
Patches
Plain Diff
Changed generate operations
parent
d5062ced
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!1
40-key-storage-service-api
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
handler/generate_certificate.go
+4
-33
4 additions, 33 deletions
handler/generate_certificate.go
handler/generate_keypair.go
+17
-28
17 additions, 28 deletions
handler/generate_keypair.go
server/server_test.go
+2
-2
2 additions, 2 deletions
server/server_test.go
with
23 additions
and
63 deletions
handler/generate_certificate.go
+
4
−
33
View file @
5629985f
...
...
@@ -47,18 +47,7 @@ func (s *KeyStorageServerImpl) GenerateCertificate(ctx context.Context, in *api.
generateCertificateResponse
:=
&
api
.
GenerateCertificateResponse
{}
// Get and decrypt aes key
encryptedAesKeyMessage
:=
&
api
.
Key
{}
data
,
_
:=
client
.
DoGetDataCall
(
"keys"
,
in
.
Uuid
+
"/aeskey"
)
if
data
.
Errors
!=
""
{
generateCertificateResponse
.
StatusList
=
utils
.
AddStatus
(
generateCertificateResponse
.
StatusList
,
"400"
,
api
.
StatusType_ERROR
,
data
.
Errors
)
return
generateCertificateResponse
,
nil
}
proto
.
Unmarshal
(
data
.
Data
.
Data
,
encryptedAesKeyMessage
)
aesKeyBytes
,
err
:=
rsaDecryptWithServerKey
(
s
.
VereignPrivateKeyFilePath
,
encryptedAesKeyMessage
.
Content
,
[]
byte
(
"aeskeys"
))
aesKeyBytes
,
err
:=
rsaDecryptWithServerKey
(
s
.
VereignPrivateKeyFilePath
,
in
.
EncryptedAesKey
,
[]
byte
(
"aeskeys"
))
if
err
!=
nil
{
generateCertificateResponse
.
StatusList
=
utils
.
AddStatus
(
generateCertificateResponse
.
StatusList
,
"400"
,
api
.
StatusType_ERROR
,
err
.
Error
())
...
...
@@ -67,7 +56,7 @@ func (s *KeyStorageServerImpl) GenerateCertificate(ctx context.Context, in *api.
// Get and decrypt rsa private key
encryptedPrivateKeyMessage
:=
&
api
.
Key
{}
data
,
_
=
client
.
DoGetDataCall
(
"keys"
,
in
.
Uuid
+
"/"
+
api
.
KeyType
.
String
(
api
.
KeyType_PRIVATE
))
data
,
_
:
=
client
.
DoGetDataCall
(
"keys"
,
in
.
Uuid
+
"/"
+
api
.
KeyType
.
String
(
api
.
KeyType_PRIVATE
))
if
data
.
Errors
!=
""
{
generateCertificateResponse
.
StatusList
=
utils
.
AddStatus
(
generateCertificateResponse
.
StatusList
,
"400"
,
api
.
StatusType_ERROR
,
data
.
Errors
)
...
...
@@ -75,16 +64,7 @@ func (s *KeyStorageServerImpl) GenerateCertificate(ctx context.Context, in *api.
}
proto
.
Unmarshal
(
data
.
Data
.
Data
,
encryptedPrivateKeyMessage
)
nonce
:=
&
api
.
Key
{}
data
,
_
=
client
.
DoGetDataCall
(
"keys"
,
in
.
Uuid
+
"/privatekey_nonce"
)
if
data
.
Errors
!=
""
{
generateCertificateResponse
.
StatusList
=
utils
.
AddStatus
(
generateCertificateResponse
.
StatusList
,
"400"
,
api
.
StatusType_ERROR
,
data
.
Errors
)
return
generateCertificateResponse
,
nil
}
proto
.
Unmarshal
(
data
.
Data
.
Data
,
nonce
)
privateKeyBytes
,
err
:=
aesDecrypt
(
aesKeyBytes
,
nonce
.
Content
,
encryptedPrivateKeyMessage
.
Content
)
privateKeyBytes
,
err
:=
aesDecrypt
(
aesKeyBytes
,
in
.
PrivateKeyNonce
,
encryptedPrivateKeyMessage
.
Content
)
if
err
!=
nil
{
generateCertificateResponse
.
StatusList
=
utils
.
AddStatus
(
generateCertificateResponse
.
StatusList
,
"400"
,
api
.
StatusType_ERROR
,
err
.
Error
())
...
...
@@ -101,16 +81,7 @@ func (s *KeyStorageServerImpl) GenerateCertificate(ctx context.Context, in *api.
}
proto
.
Unmarshal
(
data
.
Data
.
Data
,
encryptedPublicKeyMessage
)
nonce
=
&
api
.
Key
{}
data
,
_
=
client
.
DoGetDataCall
(
"keys"
,
in
.
Uuid
+
"/publickey_nonce"
)
if
data
.
Errors
!=
""
{
generateCertificateResponse
.
StatusList
=
utils
.
AddStatus
(
generateCertificateResponse
.
StatusList
,
"400"
,
api
.
StatusType_ERROR
,
data
.
Errors
)
return
generateCertificateResponse
,
nil
}
proto
.
Unmarshal
(
data
.
Data
.
Data
,
nonce
)
publicKeyBytes
,
err
:=
aesDecrypt
(
aesKeyBytes
,
nonce
.
Content
,
encryptedPublicKeyMessage
.
Content
)
publicKeyBytes
,
err
:=
aesDecrypt
(
aesKeyBytes
,
in
.
PublicKeyNonce
,
encryptedPublicKeyMessage
.
Content
)
if
err
!=
nil
{
generateCertificateResponse
.
StatusList
=
utils
.
AddStatus
(
generateCertificateResponse
.
StatusList
,
"400"
,
api
.
StatusType_ERROR
,
err
.
Error
())
...
...
This diff is collapsed.
Click to expand it.
handler/generate_keypair.go
+
17
−
28
View file @
5629985f
...
...
@@ -58,37 +58,21 @@ func (s *KeyStorageServerImpl) GenerateKeyPair(ctx context.Context, in *api.Gene
generateKeyPairResponse
.
StatusList
=
utils
.
AddStatus
(
generateKeyPairResponse
.
StatusList
,
"500"
,
api
.
StatusType_ERROR
,
err
.
Error
())
}
encryptedAesKeyBytes
,
err
:=
rsaEncryptWithServerKey
(
s
.
VereignCertFilePath
,
aesKeyBytes
,
[]
byte
(
"aeskeys"
))
encryptedPrivateKeyBytes
,
privateKeyNonce
,
err
:=
aesEncrypt
(
aesKeyBytes
,
privateKeyBytes
)
if
err
!=
nil
{
generateKeyPairResponse
.
StatusList
=
utils
.
AddStatus
(
generateKeyPairResponse
.
StatusList
,
"500"
,
api
.
StatusType_ERROR
,
err
.
Error
())
return
generateKeyPairResponse
,
nil
}
encryptedAesKey
:=
&
api
.
Key
{
Content
:
encryptedAesKeyBytes
}
result
,
errors
,
err
:=
client
.
DoPutDataCall
(
"keys"
,
uuid
+
"/aeskey"
,
encryptedAesKey
,
versions
.
EntitiesManagementAgentApiVersion
)
encryptedPrivateKey
:=
&
api
.
Key
{
Content
:
encryptedPrivateKeyBytes
}
result
,
errors
,
err
:=
client
.
DoPutDataCall
(
"keys"
,
uuid
+
"/"
+
api
.
KeyType
.
String
(
api
.
KeyType_PRIVATE
),
encryptedPrivateKey
,
versions
.
EntitiesManagementAgentApiVersion
)
generateKeyPairResponse
.
StatusList
=
handlePutDataErrors
(
generateKeyPairResponse
.
StatusList
,
errors
,
err
)
publicKeyNonce
:=
[]
byte
{}
if
generateKeyPairResponse
.
StatusList
==
nil
||
len
(
generateKeyPairResponse
.
StatusList
)
==
0
{
encryptedPrivateKeyBytes
,
nonce
,
err
:=
aesEncrypt
(
aesKeyBytes
,
privateKeyBytes
)
if
err
!=
nil
{
generateKeyPairResponse
.
StatusList
=
utils
.
AddStatus
(
generateKeyPairResponse
.
StatusList
,
"500"
,
api
.
StatusType_ERROR
,
err
.
Error
())
return
generateKeyPairResponse
,
nil
}
encryptedPrivateKey
:=
&
api
.
Key
{
Content
:
encryptedPrivateKeyBytes
}
result
,
errors
,
err
=
client
.
DoPutDataCall
(
"keys"
,
uuid
+
"/"
+
api
.
KeyType
.
String
(
api
.
KeyType_PRIVATE
),
encryptedPrivateKey
,
versions
.
EntitiesManagementAgentApiVersion
)
generateKeyPairResponse
.
StatusList
=
handlePutDataErrors
(
generateKeyPairResponse
.
StatusList
,
errors
,
err
)
if
generateKeyPairResponse
.
StatusList
==
nil
||
len
(
generateKeyPairResponse
.
StatusList
)
==
0
{
nonceMessage
:=
&
api
.
Key
{
Content
:
nonce
}
result
,
errors
,
err
=
client
.
DoPutDataCall
(
"keys"
,
uuid
+
"/privatekey_nonce"
,
nonceMessage
,
versions
.
EntitiesManagementAgentApiVersion
)
generateKeyPairResponse
.
StatusList
=
handlePutDataErrors
(
generateKeyPairResponse
.
StatusList
,
errors
,
err
)
}
}
if
generateKeyPairResponse
.
StatusList
==
nil
||
len
(
generateKeyPairResponse
.
StatusList
)
==
0
{
encryptedPublicKeyBytes
,
nonce
,
err
:=
aesEncrypt
(
aesKeyBytes
,
publicKeyBytes
)
encryptedPublicKeyBytes
,
publicKeyNonceLocal
,
err
:=
aesEncrypt
(
aesKeyBytes
,
publicKeyBytes
)
publicKeyNonce
=
publicKeyNonceLocal
if
err
!=
nil
{
generateKeyPairResponse
.
StatusList
=
utils
.
AddStatus
(
generateKeyPairResponse
.
StatusList
,
"500"
,
api
.
StatusType_ERROR
,
err
.
Error
())
...
...
@@ -97,15 +81,20 @@ func (s *KeyStorageServerImpl) GenerateKeyPair(ctx context.Context, in *api.Gene
encryptedPublicKey
:=
&
api
.
Key
{
Content
:
encryptedPublicKeyBytes
}
result
,
errors
,
err
=
client
.
DoPutDataCall
(
"keys"
,
uuid
+
"/"
+
api
.
KeyType
.
String
(
api
.
KeyType_PUBLIC
),
encryptedPublicKey
,
versions
.
EntitiesManagementAgentApiVersion
)
generateKeyPairResponse
.
StatusList
=
handlePutDataErrors
(
generateKeyPairResponse
.
StatusList
,
errors
,
err
)
if
generateKeyPairResponse
.
StatusList
==
nil
||
len
(
generateKeyPairResponse
.
StatusList
)
==
0
{
nonceMessage
:=
&
api
.
Key
{
Content
:
nonce
}
result
,
errors
,
err
=
client
.
DoPutDataCall
(
"keys"
,
uuid
+
"/publickey_nonce"
,
nonceMessage
,
versions
.
EntitiesManagementAgentApiVersion
)
generateKeyPairResponse
.
StatusList
=
handlePutDataErrors
(
generateKeyPairResponse
.
StatusList
,
errors
,
err
)
}
}
encryptedAesKeyBytes
,
err
:=
rsaEncryptWithServerKey
(
s
.
VereignCertFilePath
,
aesKeyBytes
,
[]
byte
(
"aeskeys"
))
if
err
!=
nil
{
generateKeyPairResponse
.
StatusList
=
utils
.
AddStatus
(
generateKeyPairResponse
.
StatusList
,
"500"
,
api
.
StatusType_ERROR
,
err
.
Error
())
return
generateKeyPairResponse
,
nil
}
if
generateKeyPairResponse
.
StatusList
==
nil
||
len
(
generateKeyPairResponse
.
StatusList
)
==
0
{
generateKeyPairResponse
.
Uuid
=
uuid
generateKeyPairResponse
.
EncryptedAesKey
=
encryptedAesKeyBytes
generateKeyPairResponse
.
PrivateKeyNonce
=
privateKeyNonce
generateKeyPairResponse
.
PublicKeyNonce
=
publicKeyNonce
generateKeyPairResponse
.
StatusList
=
utils
.
AddStatus
(
generateKeyPairResponse
.
StatusList
,
"200"
,
api
.
StatusType_INFO
,
result
)
}
...
...
This diff is collapsed.
Click to expand it.
server/server_test.go
+
2
−
2
View file @
5629985f
...
...
@@ -155,7 +155,7 @@ func TestGenerateKeyPairAndCertificate(t *testing.T) {
keyStorageClient
.
SetUpClient
(
keyStorageAuth
,
keyStorageGrpcAddress
,
certFilePath
)
defer
keyStorageClient
.
CloseClient
()
uuid
,
statusList
,
_
:=
keyStorageClient
.
DoGenerateKeyPair
(
2048
)
uuid
,
encryptedAesKey
,
privateKeyNonce
,
publicKeyNonce
,
statusList
,
_
:=
keyStorageClient
.
DoGenerateKeyPair
(
2048
)
for
_
,
status
:=
range
statusList
{
if
status
.
StatusType
==
ksapi
.
StatusType_ERROR
{
t
.
Errorf
(
"DoGenerateKeyPair, returned error: %s."
,
status
.
Code
+
":"
+
status
.
Description
)
...
...
@@ -214,7 +214,7 @@ func TestGenerateKeyPairAndCertificate(t *testing.T) {
Host
:
"abcde.com"
,
}
statusList
,
_
=
keyStorageClient
.
DoGenerateCertificate
(
uuid
,
certificateData
)
statusList
,
_
=
keyStorageClient
.
DoGenerateCertificate
(
uuid
,
certificateData
,
encryptedAesKey
,
privateKeyNonce
,
publicKeyNonce
)
for
_
,
status
:=
range
statusList
{
if
status
.
StatusType
==
ksapi
.
StatusType_ERROR
{
t
.
Errorf
(
"DoGenerateCertificate, returned error: %s."
,
status
.
Code
+
":"
+
status
.
Description
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment