Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
2f6b8edc
Commit
2f6b8edc
authored
Aug 24, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use base64 and 32 bytes for secret
parent
77026839
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
7 deletions
+15
-7
internal/api/secret.go
internal/api/secret.go
+14
-6
testdata/test-secret
testdata/test-secret
+1
-1
No files found.
internal/api/secret.go
View file @
2f6b8edc
package
api
import
(
"encoding/base64"
"fmt"
"io/ioutil"
"sync"
)
const
numSecretBytes
=
64
const
numSecretBytes
=
32
type
Secret
struct
{
File
string
...
...
@@ -29,17 +30,24 @@ func (s *Secret) getBytes() []byte {
}
func
(
s
*
Secret
)
setBytes
()
([]
byte
,
error
)
{
bytes
,
err
:=
ioutil
.
ReadFile
(
s
.
File
)
b
ase64B
ytes
,
err
:=
ioutil
.
ReadFile
(
s
.
File
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"read Secret.File: %v"
,
err
)
}
if
n
:=
len
(
bytes
);
n
!=
numSecretBytes
{
return
nil
,
fmt
.
Errorf
(
"expected %d bytes in %s, found %d"
,
bytes
,
s
.
File
,
n
)
secretBytes
:=
make
([]
byte
,
base64
.
StdEncoding
.
DecodedLen
(
len
(
base64Bytes
)))
n
,
err
:=
base64
.
StdEncoding
.
Decode
(
secretBytes
,
base64Bytes
)
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"decode secret: %v"
,
err
)
}
if
n
!=
numSecretBytes
{
return
nil
,
fmt
.
Errorf
(
"expected %d secretBytes in %s, found %d"
,
numSecretBytes
,
s
.
File
,
n
)
}
s
.
Lock
()
defer
s
.
Unlock
()
s
.
bytes
=
b
ytes
s
.
bytes
=
secretB
ytes
return
b
ytes
,
nil
return
secretB
ytes
,
nil
}
testdata/test-secret
View file @
2f6b8edc
AՃ+vy'jo8Bp"j6Slt܄&j˜;4/
\ No newline at end of file
+M8OJgJxoxdDRgOR0UT8sDbAgp/63y/XUNE3d8+tawA=
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment