-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathactivation_service.go
77 lines (60 loc) · 1.91 KB
/
activation_service.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package pepgo
import (
"crypto/hmac"
"crypto/sha256"
"log"
"github.com/stevenvegt/pep-go/curve"
)
type ActivationServiceKeys struct {
// Y is an ElGamal public key called Identity Private Public key
Y curve.PublicKey
// Z is an ElGamal public key called Pseudonym Private Public key
Z curve.PublicKey
// AAm is an HMAC master key called Authentication provider Adherence Master
// key. The master key AAM is used by BSN-L to derive for each authentica-
// tion provider a key AADi called Authentication provider Adherence Derived
// key. The AADi key ensures that PI/PP/PIPs are authentication provider specific
AAm curve.HMACKey
}
// IActivationService is an interface for the activation service
// The activation service create polymorphic pseudonyms and identities for the BSN for AuthProviders
type IActivationService interface {
Activate(ActivationRequest) (ActivationResponse, error)
SetKeys(ActivationServiceKeys)
IIdentifiable
}
type ActivationService struct {
keys ActivationServiceKeys
}
func NewActivationService() IActivationService {
return &ActivationService{}
}
func calcDerivedKey(key curve.HMACKey, identifier []byte) curve.HMACKey {
log.Printf("calclDerivedKey, key: %x, identifier: %s\n", key, identifier)
mac := hmac.New(sha256.New, key.Bytes())
mac.Write(identifier)
sum := mac.Sum(nil)
dk := curve.HMACKey{}
dk.SetBytes(sum)
return dk
}
func (as ActivationService) Activate(req ActivationRequest) (ActivationResponse, error) {
log.Println("OP: Activate")
// Embed
p := curve.Embed([]byte(req.Identifier))
AAdi := calcDerivedKey(as.keys.AAm, []byte(req.APid))
p = curve.Unshuffle(p, AAdi)
c, err := curve.Encrypt(as.keys.Y, p)
if err != nil {
return ActivationResponse{}, err
}
return ActivationResponse{
PI: c,
}, nil
}
func (as ActivationService) GetIdentifier() string {
return "AS1"
}
func (as *ActivationService) SetKeys(keys ActivationServiceKeys) {
as.keys = keys
}