Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
688d798f
Commit
688d798f
authored
Oct 17, 2016
by
Eric Chiang
Committed by
GitHub
Oct 17, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #620 from ericchiang/dev-fix-rotation-polling
server: fix key rotation polling
parents
3e94e65b
892fa3fe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
rotation.go
server/rotation.go
+9
-9
No files found.
server/rotation.go
View file @
688d798f
...
...
@@ -20,7 +20,7 @@ import (
// often to rotate them, and how long they can validate signatures after rotation.
type
rotationStrategy
struct
{
// Time between rotations.
period
time
.
Duration
rotationFrequency
time
.
Duration
// After being rotated how long can a key validate signatues?
verifyFor
time
.
Duration
...
...
@@ -34,18 +34,18 @@ type rotationStrategy struct {
func
staticRotationStrategy
(
key
*
rsa
.
PrivateKey
)
rotationStrategy
{
return
rotationStrategy
{
// Setting these values to 100 years is easier than having a flag indicating no rotation.
period
:
time
.
Hour
*
8760
*
100
,
verifyFor
:
time
.
Hour
*
8760
*
100
,
key
:
func
()
(
*
rsa
.
PrivateKey
,
error
)
{
return
key
,
nil
},
rotationFrequency
:
time
.
Hour
*
8760
*
100
,
verifyFor
:
time
.
Hour
*
8760
*
100
,
key
:
func
()
(
*
rsa
.
PrivateKey
,
error
)
{
return
key
,
nil
},
}
}
// defaultRotationStrategy returns a strategy which rotates keys every provided period,
// holding onto the public parts for some specified amount of time.
func
defaultRotationStrategy
(
rotation
Period
,
verifyFor
time
.
Duration
)
rotationStrategy
{
func
defaultRotationStrategy
(
rotation
Frequency
,
verifyFor
time
.
Duration
)
rotationStrategy
{
return
rotationStrategy
{
period
:
rotationPeriod
,
verifyFor
:
verifyFor
,
rotationFrequency
:
rotationFrequency
,
verifyFor
:
verifyFor
,
key
:
func
()
(
*
rsa
.
PrivateKey
,
error
)
{
return
rsa
.
GenerateKey
(
rand
.
Reader
,
2048
)
},
...
...
@@ -76,7 +76,7 @@ func startKeyRotation(ctx context.Context, s storage.Storage, strategy rotationS
select
{
case
<-
ctx
.
Done
()
:
return
case
<-
time
.
After
(
strategy
.
period
)
:
case
<-
time
.
After
(
time
.
Second
*
30
)
:
if
err
:=
rotater
.
rotate
();
err
!=
nil
{
log
.
Printf
(
"failed to rotate keys: %v"
,
err
)
}
...
...
@@ -145,7 +145,7 @@ func (k keyRotater) rotate() error {
keys
.
VerificationKeys
=
append
(
keys
.
VerificationKeys
,
verificationKey
)
}
nextRotation
=
k
.
now
()
.
Add
(
k
.
strategy
.
period
)
nextRotation
=
k
.
now
()
.
Add
(
k
.
strategy
.
rotationFrequency
)
keys
.
SigningKey
=
priv
keys
.
SigningKeyPub
=
pub
keys
.
NextRotation
=
nextRotation
...
...
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