本文整理汇总了Golang中github.com/yahoo/coname/proto.EncodedEntry类的典型用法代码示例。如果您正苦于以下问题:Golang EncodedEntry类的具体用法?Golang EncodedEntry怎么用?Golang EncodedEntry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EncodedEntry类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
configPathPtr := flag.String("config", "clientconfig.json", "path to config file")
name := flag.String("name", "[email protected]", "name to be looked up")
lookupOnly := flag.Bool("lookup", false, "only lookup the name")
flag.Parse()
timeOut := 10 * time.Second
configReader, err := os.Open(*configPathPtr)
if err != nil {
log.Fatalf("Failed to open configuration file: %s", err)
}
cfg := &proto.Config{}
err = jsonpb.Unmarshal(configReader, cfg)
if err != nil {
log.Fatalf("Failed to parse configuration file: %s", err)
}
certFile := "ca.crt.pem"
caCertPEM, err := ioutil.ReadFile(certFile)
if err != nil {
log.Fatalf("couldn't read certs from %s", certFile)
}
caCertDER, caCertPEM := pem.Decode(caCertPEM)
if caCertDER == nil {
log.Fatalf("failed to parse key PEM")
}
caCert, err := x509.ParseCertificate(caCertDER.Bytes)
if err != nil {
log.Fatal(err)
}
caPool := x509.NewCertPool()
caPool.AddCert(caCert)
realm := cfg.Realms[0]
clientTLS, err := realm.ClientTLS.Config(getKey)
if err != nil {
log.Fatal(err)
}
conn, err := grpc.Dial(realm.Addr, grpc.WithTransportCredentials(credentials.NewTLS(clientTLS)), grpc.WithTimeout(timeOut))
if err != nil {
log.Fatal(err)
}
publicC := proto.NewE2EKSPublicClient(conn)
// First, do a lookup to retrieve the index
lookup, err := publicC.Lookup(context.Background(), &proto.LookupRequest{
UserId: *name,
// We don't care about any signatures here; the server just needs to tell us the index.
// We could just give an empty quorum requirement if we wanted (although I guess the
// spec actually disallows that).
QuorumRequirement: realm.VerificationPolicy.GetQuorum(),
})
if err != nil {
log.Fatal(err)
}
fmt.Printf("looking up %s:\n", *name)
keys, err := coname.VerifyLookup(cfg, *name, lookup, time.Now())
if err != nil {
log.Fatal(err)
}
if keys == nil {
fmt.Printf("not present\n")
} else {
fmt.Printf("keys: %s\n", keys)
}
index := lookup.Index
if *lookupOnly {
return
}
// Then, do the actual update
nonce := make([]byte, 16)
_, err = rand.Read(nonce)
if err != nil {
log.Fatal(err)
}
profile := proto.EncodedProfile{
Profile: proto.Profile{
Nonce: nonce,
Keys: map[string][]byte{"abc": []byte("foo bar"), "xyz": []byte("TEST 456")},
},
}
profile.UpdateEncoding()
var commitment [64]byte
sha3.ShakeSum256(commitment[:], profile.Encoding)
var version uint64
if lookup.Entry != nil {
version = lookup.Entry.Version + 1
}
entry := proto.EncodedEntry{
Entry: proto.Entry{
Index: index,
Version: version,
UpdatePolicy: &proto.AuthorizationPolicy{
PublicKeys: make(map[uint64]*proto.PublicKey),
PolicyType: &proto.AuthorizationPolicy_Quorum{
Quorum: &proto.QuorumExpr{
Threshold: 0,
//.........这里部分代码省略.........
示例2: doUpdate
func doUpdate(
t *testing.T, ks *Keyserver, clientConfig *proto.Config, clientTLS *tls.Config, caPool *x509.CertPool, now time.Time,
name string, sk *[ed25519.PrivateKeySize]byte, pk *proto.PublicKey, version uint64, profileContents proto.Profile,
) (*proto.EncodedEntry, *proto.EncodedProfile) {
conn, err := grpc.Dial(ks.publicListen.Addr().String(), grpc.WithTransportCredentials(credentials.NewTLS(clientTLS)))
if err != nil {
t.Fatal(err)
}
publicC := proto.NewE2EKSPublicClient(conn)
// First, do a lookup to retrieve the index
lookup, err := publicC.Lookup(context.Background(), &proto.LookupRequest{
UserId: name,
// We don't care about any signatures here; the server just needs to tell us the index.
QuorumRequirement: &proto.QuorumExpr{
Threshold: 0,
Candidates: []uint64{},
Subexpressions: []*proto.QuorumExpr{},
},
})
if err != nil {
t.Fatal(err)
}
index := lookup.Index
// Do the update
var keyidBytes [8]byte
sha3.ShakeSum256(keyidBytes[:], proto.MustMarshal(pk))
keyid := binary.BigEndian.Uint64(keyidBytes[:8])
profile := proto.EncodedProfile{
Profile: profileContents,
}
profile.UpdateEncoding()
var commitment [64]byte
sha3.ShakeSum256(commitment[:], profile.Encoding)
entry := proto.EncodedEntry{
Entry: proto.Entry{
Index: index,
Version: version,
UpdatePolicy: &proto.AuthorizationPolicy{
PublicKeys: map[uint64]*proto.PublicKey{keyid: pk},
PolicyType: &proto.AuthorizationPolicy_Quorum{Quorum: &proto.QuorumExpr{
Threshold: 1,
Candidates: []uint64{keyid},
Subexpressions: []*proto.QuorumExpr{},
},
}},
ProfileCommitment: commitment[:],
},
}
entry.UpdateEncoding()
proof, err := publicC.Update(context.Background(), &proto.UpdateRequest{
Update: &proto.SignedEntryUpdate{
NewEntry: entry,
Signatures: map[uint64][]byte{keyid: ed25519.Sign(sk, entry.Encoding)[:]},
},
Profile: profile,
LookupParameters: &proto.LookupRequest{
UserId: name,
QuorumRequirement: clientConfig.Realms[0].VerificationPolicy.GetQuorum(),
},
})
if err != nil {
t.Fatal(err)
}
if got, want := proof.Profile.Encoding, profile.Encoding; !bytes.Equal(got, want) {
t.Errorf("updated profile didn't roundtrip: %x != %x", got, want)
}
_, err = coname.VerifyLookup(clientConfig, name, proof, now)
if err != nil {
t.Fatal(err)
}
return &entry, &profile
}
示例3: TestKeyserverUpdateFailsWithoutVersionIncrease
func TestKeyserverUpdateFailsWithoutVersionIncrease(t *testing.T) {
nReplicas := 3
cfgs, gks, ck, clientConfig, _, caPool, _, teardown := setupKeyservers(t, nReplicas)
defer teardown()
logs, dbs, clks, _, teardown2 := setupRaftLogCluster(t, nReplicas, 0)
defer teardown2()
kss := []*Keyserver{}
for i := range cfgs {
ks, err := Open(cfgs[i], dbs[i], logs[i], clientConfig.Realms[0].VerificationPolicy, clks[i], gks[i], nil)
if err != nil {
t.Fatal(err)
}
ks.insecureSkipEmailProof = true
ks.Start()
defer ks.Stop()
kss = append(kss, ks)
}
stop := stoppableSyncedClocks(clks)
defer close(stop)
waitForFirstEpoch(kss[0], clientConfig.Realms[0].VerificationPolicy.Quorum)
clientTLS, err := clientConfig.Realms[0].ClientTLS.Config(ck)
if err != nil {
t.Fatal(err)
}
doUpdate(t, kss[0], clientConfig, clientTLS, caPool, clks[0].Now(), alice, 0, proto.Profile{
Nonce: []byte("noncenoncenonceNONCE"),
Keys: map[string][]byte{"abc": []byte{1, 2, 3}, "xyz": []byte("TEST 456")},
})
conn, err := grpc.Dial(kss[1].publicListen.Addr().String(), grpc.WithTransportCredentials(credentials.NewTLS(clientTLS)))
if err != nil {
t.Fatal(err)
}
profile := proto.EncodedProfile{
Profile: proto.Profile{
Nonce: []byte("NONCE"),
Keys: map[string][]byte{"abc": []byte{3, 2, 3}, "xyz": []byte("TEST 456")},
},
}
profile.UpdateEncoding()
var commitment [64]byte
sha3.ShakeSum256(commitment[:], profile.Encoding)
entry := proto.EncodedEntry{
Entry: proto.Entry{
Version: 0,
UpdatePolicy: &proto.AuthorizationPolicy{
PublicKeys: make(map[uint64]*proto.PublicKey),
Quorum: &proto.QuorumExpr{
Threshold: 0,
Candidates: []uint64{},
Subexpressions: []*proto.QuorumExpr{},
},
},
ProfileCommitment: commitment[:],
},
}
entry.UpdateEncoding()
updateC := proto.NewE2EKSPublicClient(conn)
_, err = updateC.Update(context.Background(), &proto.UpdateRequest{
Update: &proto.SignedEntryUpdate{
NewEntry: entry,
Signatures: make(map[uint64][]byte),
},
Profile: profile,
LookupParameters: &proto.LookupRequest{
UserId: alice,
QuorumRequirement: clientConfig.Realms[0].VerificationPolicy.Quorum,
},
})
if err == nil {
t.Fatalf("update went through despite failure to increment version")
}
}