repo
stringlengths 5
54
| path
stringlengths 4
155
| func_name
stringlengths 1
118
| original_string
stringlengths 52
85.5k
| language
stringclasses 1
value | code
stringlengths 52
85.5k
| code_tokens
list | docstring
stringlengths 6
2.61k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
theupdateframework/notary
|
tuf/tuf.go
|
InitTargets
|
func (tr *Repo) InitTargets(role data.RoleName) (*data.SignedTargets, error) {
if !data.IsDelegation(role) && role != data.CanonicalTargetsRole {
return nil, data.ErrInvalidRole{
Role: role,
Reason: fmt.Sprintf("role is not a valid targets role name: %s", role.String()),
}
}
targets := data.NewTargets()
tr.Targets[role] = targets
return targets, nil
}
|
go
|
func (tr *Repo) InitTargets(role data.RoleName) (*data.SignedTargets, error) {
if !data.IsDelegation(role) && role != data.CanonicalTargetsRole {
return nil, data.ErrInvalidRole{
Role: role,
Reason: fmt.Sprintf("role is not a valid targets role name: %s", role.String()),
}
}
targets := data.NewTargets()
tr.Targets[role] = targets
return targets, nil
}
|
[
"func",
"(",
"tr",
"*",
"Repo",
")",
"InitTargets",
"(",
"role",
"data",
".",
"RoleName",
")",
"(",
"*",
"data",
".",
"SignedTargets",
",",
"error",
")",
"{",
"if",
"!",
"data",
".",
"IsDelegation",
"(",
"role",
")",
"&&",
"role",
"!=",
"data",
".",
"CanonicalTargetsRole",
"{",
"return",
"nil",
",",
"data",
".",
"ErrInvalidRole",
"{",
"Role",
":",
"role",
",",
"Reason",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"role",
".",
"String",
"(",
")",
")",
",",
"}",
"\n",
"}",
"\n",
"targets",
":=",
"data",
".",
"NewTargets",
"(",
")",
"\n",
"tr",
".",
"Targets",
"[",
"role",
"]",
"=",
"targets",
"\n",
"return",
"targets",
",",
"nil",
"\n",
"}"
] |
// InitTargets initializes an empty targets, and returns the new empty target
|
[
"InitTargets",
"initializes",
"an",
"empty",
"targets",
"and",
"returns",
"the",
"new",
"empty",
"target"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L578-L588
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
InitSnapshot
|
func (tr *Repo) InitSnapshot() error {
if tr.Root == nil {
return ErrNotLoaded{Role: data.CanonicalRootRole}
}
root, err := tr.Root.ToSigned()
if err != nil {
return err
}
if _, ok := tr.Targets[data.CanonicalTargetsRole]; !ok {
return ErrNotLoaded{Role: data.CanonicalTargetsRole}
}
targets, err := tr.Targets[data.CanonicalTargetsRole].ToSigned()
if err != nil {
return err
}
snapshot, err := data.NewSnapshot(root, targets)
if err != nil {
return err
}
tr.Snapshot = snapshot
return nil
}
|
go
|
func (tr *Repo) InitSnapshot() error {
if tr.Root == nil {
return ErrNotLoaded{Role: data.CanonicalRootRole}
}
root, err := tr.Root.ToSigned()
if err != nil {
return err
}
if _, ok := tr.Targets[data.CanonicalTargetsRole]; !ok {
return ErrNotLoaded{Role: data.CanonicalTargetsRole}
}
targets, err := tr.Targets[data.CanonicalTargetsRole].ToSigned()
if err != nil {
return err
}
snapshot, err := data.NewSnapshot(root, targets)
if err != nil {
return err
}
tr.Snapshot = snapshot
return nil
}
|
[
"func",
"(",
"tr",
"*",
"Repo",
")",
"InitSnapshot",
"(",
")",
"error",
"{",
"if",
"tr",
".",
"Root",
"==",
"nil",
"{",
"return",
"ErrNotLoaded",
"{",
"Role",
":",
"data",
".",
"CanonicalRootRole",
"}",
"\n",
"}",
"\n",
"root",
",",
"err",
":=",
"tr",
".",
"Root",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"tr",
".",
"Targets",
"[",
"data",
".",
"CanonicalTargetsRole",
"]",
";",
"!",
"ok",
"{",
"return",
"ErrNotLoaded",
"{",
"Role",
":",
"data",
".",
"CanonicalTargetsRole",
"}",
"\n",
"}",
"\n",
"targets",
",",
"err",
":=",
"tr",
".",
"Targets",
"[",
"data",
".",
"CanonicalTargetsRole",
"]",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"snapshot",
",",
"err",
":=",
"data",
".",
"NewSnapshot",
"(",
"root",
",",
"targets",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"tr",
".",
"Snapshot",
"=",
"snapshot",
"\n",
"return",
"nil",
"\n",
"}"
] |
// InitSnapshot initializes a snapshot based on the current root and targets
|
[
"InitSnapshot",
"initializes",
"a",
"snapshot",
"based",
"on",
"the",
"current",
"root",
"and",
"targets"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L591-L613
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
InitTimestamp
|
func (tr *Repo) InitTimestamp() error {
snap, err := tr.Snapshot.ToSigned()
if err != nil {
return err
}
timestamp, err := data.NewTimestamp(snap)
if err != nil {
return err
}
tr.Timestamp = timestamp
return nil
}
|
go
|
func (tr *Repo) InitTimestamp() error {
snap, err := tr.Snapshot.ToSigned()
if err != nil {
return err
}
timestamp, err := data.NewTimestamp(snap)
if err != nil {
return err
}
tr.Timestamp = timestamp
return nil
}
|
[
"func",
"(",
"tr",
"*",
"Repo",
")",
"InitTimestamp",
"(",
")",
"error",
"{",
"snap",
",",
"err",
":=",
"tr",
".",
"Snapshot",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"timestamp",
",",
"err",
":=",
"data",
".",
"NewTimestamp",
"(",
"snap",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"tr",
".",
"Timestamp",
"=",
"timestamp",
"\n",
"return",
"nil",
"\n",
"}"
] |
// InitTimestamp initializes a timestamp based on the current snapshot
|
[
"InitTimestamp",
"initializes",
"a",
"timestamp",
"based",
"on",
"the",
"current",
"snapshot"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L616-L628
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
TargetMeta
|
func (tr Repo) TargetMeta(role data.RoleName, path string) *data.FileMeta {
if t, ok := tr.Targets[role]; ok {
if m, ok := t.Signed.Targets[path]; ok {
return &m
}
}
return nil
}
|
go
|
func (tr Repo) TargetMeta(role data.RoleName, path string) *data.FileMeta {
if t, ok := tr.Targets[role]; ok {
if m, ok := t.Signed.Targets[path]; ok {
return &m
}
}
return nil
}
|
[
"func",
"(",
"tr",
"Repo",
")",
"TargetMeta",
"(",
"role",
"data",
".",
"RoleName",
",",
"path",
"string",
")",
"*",
"data",
".",
"FileMeta",
"{",
"if",
"t",
",",
"ok",
":=",
"tr",
".",
"Targets",
"[",
"role",
"]",
";",
"ok",
"{",
"if",
"m",
",",
"ok",
":=",
"t",
".",
"Signed",
".",
"Targets",
"[",
"path",
"]",
";",
"ok",
"{",
"return",
"&",
"m",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// TargetMeta returns the FileMeta entry for the given path in the
// targets file associated with the given role. This may be nil if
// the target isn't found in the targets file.
|
[
"TargetMeta",
"returns",
"the",
"FileMeta",
"entry",
"for",
"the",
"given",
"path",
"in",
"the",
"targets",
"file",
"associated",
"with",
"the",
"given",
"role",
".",
"This",
"may",
"be",
"nil",
"if",
"the",
"target",
"isn",
"t",
"found",
"in",
"the",
"targets",
"file",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L633-L640
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
TargetDelegations
|
func (tr Repo) TargetDelegations(role data.RoleName, path string) []*data.Role {
var roles []*data.Role
if t, ok := tr.Targets[role]; ok {
for _, r := range t.Signed.Delegations.Roles {
if r.CheckPaths(path) {
roles = append(roles, r)
}
}
}
return roles
}
|
go
|
func (tr Repo) TargetDelegations(role data.RoleName, path string) []*data.Role {
var roles []*data.Role
if t, ok := tr.Targets[role]; ok {
for _, r := range t.Signed.Delegations.Roles {
if r.CheckPaths(path) {
roles = append(roles, r)
}
}
}
return roles
}
|
[
"func",
"(",
"tr",
"Repo",
")",
"TargetDelegations",
"(",
"role",
"data",
".",
"RoleName",
",",
"path",
"string",
")",
"[",
"]",
"*",
"data",
".",
"Role",
"{",
"var",
"roles",
"[",
"]",
"*",
"data",
".",
"Role",
"\n",
"if",
"t",
",",
"ok",
":=",
"tr",
".",
"Targets",
"[",
"role",
"]",
";",
"ok",
"{",
"for",
"_",
",",
"r",
":=",
"range",
"t",
".",
"Signed",
".",
"Delegations",
".",
"Roles",
"{",
"if",
"r",
".",
"CheckPaths",
"(",
"path",
")",
"{",
"roles",
"=",
"append",
"(",
"roles",
",",
"r",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"roles",
"\n",
"}"
] |
// TargetDelegations returns a slice of Roles that are valid publishers
// for the target path provided.
|
[
"TargetDelegations",
"returns",
"a",
"slice",
"of",
"Roles",
"that",
"are",
"valid",
"publishers",
"for",
"the",
"target",
"path",
"provided",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L644-L654
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
VerifyCanSign
|
func (tr *Repo) VerifyCanSign(roleName data.RoleName) error {
var (
role data.BaseRole
err error
canonicalKeyIDs []string
)
// we only need the BaseRole part of a delegation because we're just
// checking KeyIDs
if data.IsDelegation(roleName) {
r, err := tr.GetDelegationRole(roleName)
if err != nil {
return err
}
role = r.BaseRole
} else {
role, err = tr.GetBaseRole(roleName)
}
if err != nil {
return data.ErrInvalidRole{Role: roleName, Reason: "does not exist"}
}
for keyID, k := range role.Keys {
check := []string{keyID}
if canonicalID, err := utils.CanonicalKeyID(k); err == nil {
check = append(check, canonicalID)
canonicalKeyIDs = append(canonicalKeyIDs, canonicalID)
}
for _, id := range check {
p, _, err := tr.cryptoService.GetPrivateKey(id)
if err == nil && p != nil {
return nil
}
}
}
return signed.ErrNoKeys{KeyIDs: canonicalKeyIDs}
}
|
go
|
func (tr *Repo) VerifyCanSign(roleName data.RoleName) error {
var (
role data.BaseRole
err error
canonicalKeyIDs []string
)
// we only need the BaseRole part of a delegation because we're just
// checking KeyIDs
if data.IsDelegation(roleName) {
r, err := tr.GetDelegationRole(roleName)
if err != nil {
return err
}
role = r.BaseRole
} else {
role, err = tr.GetBaseRole(roleName)
}
if err != nil {
return data.ErrInvalidRole{Role: roleName, Reason: "does not exist"}
}
for keyID, k := range role.Keys {
check := []string{keyID}
if canonicalID, err := utils.CanonicalKeyID(k); err == nil {
check = append(check, canonicalID)
canonicalKeyIDs = append(canonicalKeyIDs, canonicalID)
}
for _, id := range check {
p, _, err := tr.cryptoService.GetPrivateKey(id)
if err == nil && p != nil {
return nil
}
}
}
return signed.ErrNoKeys{KeyIDs: canonicalKeyIDs}
}
|
[
"func",
"(",
"tr",
"*",
"Repo",
")",
"VerifyCanSign",
"(",
"roleName",
"data",
".",
"RoleName",
")",
"error",
"{",
"var",
"(",
"role",
"data",
".",
"BaseRole",
"\n",
"err",
"error",
"\n",
"canonicalKeyIDs",
"[",
"]",
"string",
"\n",
")",
"\n",
"// we only need the BaseRole part of a delegation because we're just",
"// checking KeyIDs",
"if",
"data",
".",
"IsDelegation",
"(",
"roleName",
")",
"{",
"r",
",",
"err",
":=",
"tr",
".",
"GetDelegationRole",
"(",
"roleName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"role",
"=",
"r",
".",
"BaseRole",
"\n",
"}",
"else",
"{",
"role",
",",
"err",
"=",
"tr",
".",
"GetBaseRole",
"(",
"roleName",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"data",
".",
"ErrInvalidRole",
"{",
"Role",
":",
"roleName",
",",
"Reason",
":",
"\"",
"\"",
"}",
"\n",
"}",
"\n\n",
"for",
"keyID",
",",
"k",
":=",
"range",
"role",
".",
"Keys",
"{",
"check",
":=",
"[",
"]",
"string",
"{",
"keyID",
"}",
"\n",
"if",
"canonicalID",
",",
"err",
":=",
"utils",
".",
"CanonicalKeyID",
"(",
"k",
")",
";",
"err",
"==",
"nil",
"{",
"check",
"=",
"append",
"(",
"check",
",",
"canonicalID",
")",
"\n",
"canonicalKeyIDs",
"=",
"append",
"(",
"canonicalKeyIDs",
",",
"canonicalID",
")",
"\n",
"}",
"\n",
"for",
"_",
",",
"id",
":=",
"range",
"check",
"{",
"p",
",",
"_",
",",
"err",
":=",
"tr",
".",
"cryptoService",
".",
"GetPrivateKey",
"(",
"id",
")",
"\n",
"if",
"err",
"==",
"nil",
"&&",
"p",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"signed",
".",
"ErrNoKeys",
"{",
"KeyIDs",
":",
"canonicalKeyIDs",
"}",
"\n",
"}"
] |
// VerifyCanSign returns nil if the role exists and we have at least one
// signing key for the role, false otherwise. This does not check that we have
// enough signing keys to meet the threshold, since we want to support the use
// case of multiple signers for a role. It returns an error if the role doesn't
// exist or if there are no signing keys.
|
[
"VerifyCanSign",
"returns",
"nil",
"if",
"the",
"role",
"exists",
"and",
"we",
"have",
"at",
"least",
"one",
"signing",
"key",
"for",
"the",
"role",
"false",
"otherwise",
".",
"This",
"does",
"not",
"check",
"that",
"we",
"have",
"enough",
"signing",
"keys",
"to",
"meet",
"the",
"threshold",
"since",
"we",
"want",
"to",
"support",
"the",
"use",
"case",
"of",
"multiple",
"signers",
"for",
"a",
"role",
".",
"It",
"returns",
"an",
"error",
"if",
"the",
"role",
"doesn",
"t",
"exist",
"or",
"if",
"there",
"are",
"no",
"signing",
"keys",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L661-L696
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
isValidPath
|
func isValidPath(candidatePath string, delgRole data.DelegationRole) bool {
return candidatePath == "" || delgRole.CheckPaths(candidatePath)
}
|
go
|
func isValidPath(candidatePath string, delgRole data.DelegationRole) bool {
return candidatePath == "" || delgRole.CheckPaths(candidatePath)
}
|
[
"func",
"isValidPath",
"(",
"candidatePath",
"string",
",",
"delgRole",
"data",
".",
"DelegationRole",
")",
"bool",
"{",
"return",
"candidatePath",
"==",
"\"",
"\"",
"||",
"delgRole",
".",
"CheckPaths",
"(",
"candidatePath",
")",
"\n",
"}"
] |
// helper function that returns whether the delegation Role is valid against the given path
// Will return true if given an empty candidatePath
|
[
"helper",
"function",
"that",
"returns",
"whether",
"the",
"delegation",
"Role",
"is",
"valid",
"against",
"the",
"given",
"path",
"Will",
"return",
"true",
"if",
"given",
"an",
"empty",
"candidatePath"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L771-L773
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
AddTargets
|
func (tr *Repo) AddTargets(role data.RoleName, targets data.Files) (data.Files, error) {
cantSignErr := tr.VerifyCanSign(role)
if _, ok := cantSignErr.(data.ErrInvalidRole); ok {
return nil, cantSignErr
}
var needSign bool
// check existence of the role's metadata
_, ok := tr.Targets[role]
if !ok { // the targetfile may not exist yet - if not, then create it
var err error
_, err = tr.InitTargets(role)
if err != nil {
return nil, err
}
}
addedTargets := make(data.Files)
addTargetVisitor := func(targetPath string, targetMeta data.FileMeta) func(*data.SignedTargets, data.DelegationRole) interface{} {
return func(tgt *data.SignedTargets, validRole data.DelegationRole) interface{} {
// We've already validated the role's target path in our walk, so just modify the metadata
if targetMeta.Equals(tgt.Signed.Targets[targetPath]) {
// Also add to our new addedTargets map because this target was "added" successfully
addedTargets[targetPath] = targetMeta
return StopWalk{}
}
needSign = true
if cantSignErr == nil {
tgt.Signed.Targets[targetPath] = targetMeta
tgt.Dirty = true
// Also add to our new addedTargets map to keep track of every target we've added successfully
addedTargets[targetPath] = targetMeta
}
return StopWalk{}
}
}
// Walk the role tree while validating the target paths, and add all of our targets
for path, target := range targets {
tr.WalkTargets(path, role, addTargetVisitor(path, target))
if needSign && cantSignErr != nil {
return nil, cantSignErr
}
}
if len(addedTargets) != len(targets) {
return nil, fmt.Errorf("Could not add all targets")
}
return nil, nil
}
|
go
|
func (tr *Repo) AddTargets(role data.RoleName, targets data.Files) (data.Files, error) {
cantSignErr := tr.VerifyCanSign(role)
if _, ok := cantSignErr.(data.ErrInvalidRole); ok {
return nil, cantSignErr
}
var needSign bool
// check existence of the role's metadata
_, ok := tr.Targets[role]
if !ok { // the targetfile may not exist yet - if not, then create it
var err error
_, err = tr.InitTargets(role)
if err != nil {
return nil, err
}
}
addedTargets := make(data.Files)
addTargetVisitor := func(targetPath string, targetMeta data.FileMeta) func(*data.SignedTargets, data.DelegationRole) interface{} {
return func(tgt *data.SignedTargets, validRole data.DelegationRole) interface{} {
// We've already validated the role's target path in our walk, so just modify the metadata
if targetMeta.Equals(tgt.Signed.Targets[targetPath]) {
// Also add to our new addedTargets map because this target was "added" successfully
addedTargets[targetPath] = targetMeta
return StopWalk{}
}
needSign = true
if cantSignErr == nil {
tgt.Signed.Targets[targetPath] = targetMeta
tgt.Dirty = true
// Also add to our new addedTargets map to keep track of every target we've added successfully
addedTargets[targetPath] = targetMeta
}
return StopWalk{}
}
}
// Walk the role tree while validating the target paths, and add all of our targets
for path, target := range targets {
tr.WalkTargets(path, role, addTargetVisitor(path, target))
if needSign && cantSignErr != nil {
return nil, cantSignErr
}
}
if len(addedTargets) != len(targets) {
return nil, fmt.Errorf("Could not add all targets")
}
return nil, nil
}
|
[
"func",
"(",
"tr",
"*",
"Repo",
")",
"AddTargets",
"(",
"role",
"data",
".",
"RoleName",
",",
"targets",
"data",
".",
"Files",
")",
"(",
"data",
".",
"Files",
",",
"error",
")",
"{",
"cantSignErr",
":=",
"tr",
".",
"VerifyCanSign",
"(",
"role",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"cantSignErr",
".",
"(",
"data",
".",
"ErrInvalidRole",
")",
";",
"ok",
"{",
"return",
"nil",
",",
"cantSignErr",
"\n",
"}",
"\n",
"var",
"needSign",
"bool",
"\n\n",
"// check existence of the role's metadata",
"_",
",",
"ok",
":=",
"tr",
".",
"Targets",
"[",
"role",
"]",
"\n",
"if",
"!",
"ok",
"{",
"// the targetfile may not exist yet - if not, then create it",
"var",
"err",
"error",
"\n",
"_",
",",
"err",
"=",
"tr",
".",
"InitTargets",
"(",
"role",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"addedTargets",
":=",
"make",
"(",
"data",
".",
"Files",
")",
"\n",
"addTargetVisitor",
":=",
"func",
"(",
"targetPath",
"string",
",",
"targetMeta",
"data",
".",
"FileMeta",
")",
"func",
"(",
"*",
"data",
".",
"SignedTargets",
",",
"data",
".",
"DelegationRole",
")",
"interface",
"{",
"}",
"{",
"return",
"func",
"(",
"tgt",
"*",
"data",
".",
"SignedTargets",
",",
"validRole",
"data",
".",
"DelegationRole",
")",
"interface",
"{",
"}",
"{",
"// We've already validated the role's target path in our walk, so just modify the metadata",
"if",
"targetMeta",
".",
"Equals",
"(",
"tgt",
".",
"Signed",
".",
"Targets",
"[",
"targetPath",
"]",
")",
"{",
"// Also add to our new addedTargets map because this target was \"added\" successfully",
"addedTargets",
"[",
"targetPath",
"]",
"=",
"targetMeta",
"\n",
"return",
"StopWalk",
"{",
"}",
"\n",
"}",
"\n",
"needSign",
"=",
"true",
"\n",
"if",
"cantSignErr",
"==",
"nil",
"{",
"tgt",
".",
"Signed",
".",
"Targets",
"[",
"targetPath",
"]",
"=",
"targetMeta",
"\n",
"tgt",
".",
"Dirty",
"=",
"true",
"\n",
"// Also add to our new addedTargets map to keep track of every target we've added successfully",
"addedTargets",
"[",
"targetPath",
"]",
"=",
"targetMeta",
"\n",
"}",
"\n",
"return",
"StopWalk",
"{",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Walk the role tree while validating the target paths, and add all of our targets",
"for",
"path",
",",
"target",
":=",
"range",
"targets",
"{",
"tr",
".",
"WalkTargets",
"(",
"path",
",",
"role",
",",
"addTargetVisitor",
"(",
"path",
",",
"target",
")",
")",
"\n",
"if",
"needSign",
"&&",
"cantSignErr",
"!=",
"nil",
"{",
"return",
"nil",
",",
"cantSignErr",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"addedTargets",
")",
"!=",
"len",
"(",
"targets",
")",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"nil",
"\n",
"}"
] |
// AddTargets will attempt to add the given targets specifically to
// the directed role. If the metadata for the role doesn't exist yet,
// AddTargets will create one.
|
[
"AddTargets",
"will",
"attempt",
"to",
"add",
"the",
"given",
"targets",
"specifically",
"to",
"the",
"directed",
"role",
".",
"If",
"the",
"metadata",
"for",
"the",
"role",
"doesn",
"t",
"exist",
"yet",
"AddTargets",
"will",
"create",
"one",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L778-L826
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
UpdateSnapshot
|
func (tr *Repo) UpdateSnapshot(role data.RoleName, s *data.Signed) error {
jsonData, err := json.Marshal(s)
if err != nil {
return err
}
meta, err := data.NewFileMeta(bytes.NewReader(jsonData), data.NotaryDefaultHashes...)
if err != nil {
return err
}
tr.Snapshot.Signed.Meta[role.String()] = meta
tr.Snapshot.Dirty = true
return nil
}
|
go
|
func (tr *Repo) UpdateSnapshot(role data.RoleName, s *data.Signed) error {
jsonData, err := json.Marshal(s)
if err != nil {
return err
}
meta, err := data.NewFileMeta(bytes.NewReader(jsonData), data.NotaryDefaultHashes...)
if err != nil {
return err
}
tr.Snapshot.Signed.Meta[role.String()] = meta
tr.Snapshot.Dirty = true
return nil
}
|
[
"func",
"(",
"tr",
"*",
"Repo",
")",
"UpdateSnapshot",
"(",
"role",
"data",
".",
"RoleName",
",",
"s",
"*",
"data",
".",
"Signed",
")",
"error",
"{",
"jsonData",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"meta",
",",
"err",
":=",
"data",
".",
"NewFileMeta",
"(",
"bytes",
".",
"NewReader",
"(",
"jsonData",
")",
",",
"data",
".",
"NotaryDefaultHashes",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"tr",
".",
"Snapshot",
".",
"Signed",
".",
"Meta",
"[",
"role",
".",
"String",
"(",
")",
"]",
"=",
"meta",
"\n",
"tr",
".",
"Snapshot",
".",
"Dirty",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UpdateSnapshot updates the FileMeta for the given role based on the Signed object
|
[
"UpdateSnapshot",
"updates",
"the",
"FileMeta",
"for",
"the",
"given",
"role",
"based",
"on",
"the",
"Signed",
"object"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L863-L875
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
UpdateTimestamp
|
func (tr *Repo) UpdateTimestamp(s *data.Signed) error {
jsonData, err := json.Marshal(s)
if err != nil {
return err
}
meta, err := data.NewFileMeta(bytes.NewReader(jsonData), data.NotaryDefaultHashes...)
if err != nil {
return err
}
tr.Timestamp.Signed.Meta[data.CanonicalSnapshotRole.String()] = meta
tr.Timestamp.Dirty = true
return nil
}
|
go
|
func (tr *Repo) UpdateTimestamp(s *data.Signed) error {
jsonData, err := json.Marshal(s)
if err != nil {
return err
}
meta, err := data.NewFileMeta(bytes.NewReader(jsonData), data.NotaryDefaultHashes...)
if err != nil {
return err
}
tr.Timestamp.Signed.Meta[data.CanonicalSnapshotRole.String()] = meta
tr.Timestamp.Dirty = true
return nil
}
|
[
"func",
"(",
"tr",
"*",
"Repo",
")",
"UpdateTimestamp",
"(",
"s",
"*",
"data",
".",
"Signed",
")",
"error",
"{",
"jsonData",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"meta",
",",
"err",
":=",
"data",
".",
"NewFileMeta",
"(",
"bytes",
".",
"NewReader",
"(",
"jsonData",
")",
",",
"data",
".",
"NotaryDefaultHashes",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"tr",
".",
"Timestamp",
".",
"Signed",
".",
"Meta",
"[",
"data",
".",
"CanonicalSnapshotRole",
".",
"String",
"(",
")",
"]",
"=",
"meta",
"\n",
"tr",
".",
"Timestamp",
".",
"Dirty",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] |
// UpdateTimestamp updates the snapshot meta in the timestamp based on the Signed object
|
[
"UpdateTimestamp",
"updates",
"the",
"snapshot",
"meta",
"in",
"the",
"timestamp",
"based",
"on",
"the",
"Signed",
"object"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L878-L890
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
SignTargets
|
func (tr *Repo) SignTargets(role data.RoleName, expires time.Time) (*data.Signed, error) {
logrus.Debugf("sign targets called for role %s", role)
if _, ok := tr.Targets[role]; !ok {
return nil, data.ErrInvalidRole{
Role: role,
Reason: "SignTargets called with non-existent targets role",
}
}
tr.Targets[role].Signed.Expires = expires
tr.Targets[role].Signed.Version++
signed, err := tr.Targets[role].ToSigned()
if err != nil {
logrus.Debug("errored getting targets data.Signed object")
return nil, err
}
var targets data.BaseRole
if role == data.CanonicalTargetsRole {
targets, err = tr.GetBaseRole(role)
} else {
tr, err := tr.GetDelegationRole(role)
if err != nil {
return nil, err
}
targets = tr.BaseRole
}
if err != nil {
return nil, err
}
signed, err = tr.sign(signed, []data.BaseRole{targets}, nil)
if err != nil {
logrus.Debug("errored signing ", role)
return nil, err
}
tr.Targets[role].Signatures = signed.Signatures
return signed, nil
}
|
go
|
func (tr *Repo) SignTargets(role data.RoleName, expires time.Time) (*data.Signed, error) {
logrus.Debugf("sign targets called for role %s", role)
if _, ok := tr.Targets[role]; !ok {
return nil, data.ErrInvalidRole{
Role: role,
Reason: "SignTargets called with non-existent targets role",
}
}
tr.Targets[role].Signed.Expires = expires
tr.Targets[role].Signed.Version++
signed, err := tr.Targets[role].ToSigned()
if err != nil {
logrus.Debug("errored getting targets data.Signed object")
return nil, err
}
var targets data.BaseRole
if role == data.CanonicalTargetsRole {
targets, err = tr.GetBaseRole(role)
} else {
tr, err := tr.GetDelegationRole(role)
if err != nil {
return nil, err
}
targets = tr.BaseRole
}
if err != nil {
return nil, err
}
signed, err = tr.sign(signed, []data.BaseRole{targets}, nil)
if err != nil {
logrus.Debug("errored signing ", role)
return nil, err
}
tr.Targets[role].Signatures = signed.Signatures
return signed, nil
}
|
[
"func",
"(",
"tr",
"*",
"Repo",
")",
"SignTargets",
"(",
"role",
"data",
".",
"RoleName",
",",
"expires",
"time",
".",
"Time",
")",
"(",
"*",
"data",
".",
"Signed",
",",
"error",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"role",
")",
"\n",
"if",
"_",
",",
"ok",
":=",
"tr",
".",
"Targets",
"[",
"role",
"]",
";",
"!",
"ok",
"{",
"return",
"nil",
",",
"data",
".",
"ErrInvalidRole",
"{",
"Role",
":",
"role",
",",
"Reason",
":",
"\"",
"\"",
",",
"}",
"\n",
"}",
"\n",
"tr",
".",
"Targets",
"[",
"role",
"]",
".",
"Signed",
".",
"Expires",
"=",
"expires",
"\n",
"tr",
".",
"Targets",
"[",
"role",
"]",
".",
"Signed",
".",
"Version",
"++",
"\n",
"signed",
",",
"err",
":=",
"tr",
".",
"Targets",
"[",
"role",
"]",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"targets",
"data",
".",
"BaseRole",
"\n",
"if",
"role",
"==",
"data",
".",
"CanonicalTargetsRole",
"{",
"targets",
",",
"err",
"=",
"tr",
".",
"GetBaseRole",
"(",
"role",
")",
"\n",
"}",
"else",
"{",
"tr",
",",
"err",
":=",
"tr",
".",
"GetDelegationRole",
"(",
"role",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"targets",
"=",
"tr",
".",
"BaseRole",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"signed",
",",
"err",
"=",
"tr",
".",
"sign",
"(",
"signed",
",",
"[",
"]",
"data",
".",
"BaseRole",
"{",
"targets",
"}",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
",",
"role",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tr",
".",
"Targets",
"[",
"role",
"]",
".",
"Signatures",
"=",
"signed",
".",
"Signatures",
"\n",
"return",
"signed",
",",
"nil",
"\n",
"}"
] |
// SignTargets signs the targets file for the given top level or delegated targets role
|
[
"SignTargets",
"signs",
"the",
"targets",
"file",
"for",
"the",
"given",
"top",
"level",
"or",
"delegated",
"targets",
"role"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L949-L986
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
SignSnapshot
|
func (tr *Repo) SignSnapshot(expires time.Time) (*data.Signed, error) {
logrus.Debug("signing snapshot...")
signedRoot, err := tr.Root.ToSigned()
if err != nil {
return nil, err
}
err = tr.UpdateSnapshot(data.CanonicalRootRole, signedRoot)
if err != nil {
return nil, err
}
tr.Root.Dirty = false // root dirty until changes captures in snapshot
for role, targets := range tr.Targets {
signedTargets, err := targets.ToSigned()
if err != nil {
return nil, err
}
err = tr.UpdateSnapshot(role, signedTargets)
if err != nil {
return nil, err
}
targets.Dirty = false
}
tr.Snapshot.Signed.Expires = expires
tr.Snapshot.Signed.Version++
signed, err := tr.Snapshot.ToSigned()
if err != nil {
return nil, err
}
snapshot, err := tr.GetBaseRole(data.CanonicalSnapshotRole)
if err != nil {
return nil, err
}
signed, err = tr.sign(signed, []data.BaseRole{snapshot}, nil)
if err != nil {
return nil, err
}
tr.Snapshot.Signatures = signed.Signatures
return signed, nil
}
|
go
|
func (tr *Repo) SignSnapshot(expires time.Time) (*data.Signed, error) {
logrus.Debug("signing snapshot...")
signedRoot, err := tr.Root.ToSigned()
if err != nil {
return nil, err
}
err = tr.UpdateSnapshot(data.CanonicalRootRole, signedRoot)
if err != nil {
return nil, err
}
tr.Root.Dirty = false // root dirty until changes captures in snapshot
for role, targets := range tr.Targets {
signedTargets, err := targets.ToSigned()
if err != nil {
return nil, err
}
err = tr.UpdateSnapshot(role, signedTargets)
if err != nil {
return nil, err
}
targets.Dirty = false
}
tr.Snapshot.Signed.Expires = expires
tr.Snapshot.Signed.Version++
signed, err := tr.Snapshot.ToSigned()
if err != nil {
return nil, err
}
snapshot, err := tr.GetBaseRole(data.CanonicalSnapshotRole)
if err != nil {
return nil, err
}
signed, err = tr.sign(signed, []data.BaseRole{snapshot}, nil)
if err != nil {
return nil, err
}
tr.Snapshot.Signatures = signed.Signatures
return signed, nil
}
|
[
"func",
"(",
"tr",
"*",
"Repo",
")",
"SignSnapshot",
"(",
"expires",
"time",
".",
"Time",
")",
"(",
"*",
"data",
".",
"Signed",
",",
"error",
")",
"{",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"signedRoot",
",",
"err",
":=",
"tr",
".",
"Root",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"tr",
".",
"UpdateSnapshot",
"(",
"data",
".",
"CanonicalRootRole",
",",
"signedRoot",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tr",
".",
"Root",
".",
"Dirty",
"=",
"false",
"// root dirty until changes captures in snapshot",
"\n",
"for",
"role",
",",
"targets",
":=",
"range",
"tr",
".",
"Targets",
"{",
"signedTargets",
",",
"err",
":=",
"targets",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"tr",
".",
"UpdateSnapshot",
"(",
"role",
",",
"signedTargets",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"targets",
".",
"Dirty",
"=",
"false",
"\n",
"}",
"\n",
"tr",
".",
"Snapshot",
".",
"Signed",
".",
"Expires",
"=",
"expires",
"\n",
"tr",
".",
"Snapshot",
".",
"Signed",
".",
"Version",
"++",
"\n",
"signed",
",",
"err",
":=",
"tr",
".",
"Snapshot",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"snapshot",
",",
"err",
":=",
"tr",
".",
"GetBaseRole",
"(",
"data",
".",
"CanonicalSnapshotRole",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"signed",
",",
"err",
"=",
"tr",
".",
"sign",
"(",
"signed",
",",
"[",
"]",
"data",
".",
"BaseRole",
"{",
"snapshot",
"}",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tr",
".",
"Snapshot",
".",
"Signatures",
"=",
"signed",
".",
"Signatures",
"\n",
"return",
"signed",
",",
"nil",
"\n",
"}"
] |
// SignSnapshot updates the snapshot based on the current targets and root then signs it
|
[
"SignSnapshot",
"updates",
"the",
"snapshot",
"based",
"on",
"the",
"current",
"targets",
"and",
"root",
"then",
"signs",
"it"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L989-L1027
|
train
|
theupdateframework/notary
|
tuf/tuf.go
|
SignTimestamp
|
func (tr *Repo) SignTimestamp(expires time.Time) (*data.Signed, error) {
logrus.Debug("SignTimestamp")
signedSnapshot, err := tr.Snapshot.ToSigned()
if err != nil {
return nil, err
}
err = tr.UpdateTimestamp(signedSnapshot)
if err != nil {
return nil, err
}
tr.Timestamp.Signed.Expires = expires
tr.Timestamp.Signed.Version++
signed, err := tr.Timestamp.ToSigned()
if err != nil {
return nil, err
}
timestamp, err := tr.GetBaseRole(data.CanonicalTimestampRole)
if err != nil {
return nil, err
}
signed, err = tr.sign(signed, []data.BaseRole{timestamp}, nil)
if err != nil {
return nil, err
}
tr.Timestamp.Signatures = signed.Signatures
tr.Snapshot.Dirty = false // snapshot is dirty until changes have been captured in timestamp
return signed, nil
}
|
go
|
func (tr *Repo) SignTimestamp(expires time.Time) (*data.Signed, error) {
logrus.Debug("SignTimestamp")
signedSnapshot, err := tr.Snapshot.ToSigned()
if err != nil {
return nil, err
}
err = tr.UpdateTimestamp(signedSnapshot)
if err != nil {
return nil, err
}
tr.Timestamp.Signed.Expires = expires
tr.Timestamp.Signed.Version++
signed, err := tr.Timestamp.ToSigned()
if err != nil {
return nil, err
}
timestamp, err := tr.GetBaseRole(data.CanonicalTimestampRole)
if err != nil {
return nil, err
}
signed, err = tr.sign(signed, []data.BaseRole{timestamp}, nil)
if err != nil {
return nil, err
}
tr.Timestamp.Signatures = signed.Signatures
tr.Snapshot.Dirty = false // snapshot is dirty until changes have been captured in timestamp
return signed, nil
}
|
[
"func",
"(",
"tr",
"*",
"Repo",
")",
"SignTimestamp",
"(",
"expires",
"time",
".",
"Time",
")",
"(",
"*",
"data",
".",
"Signed",
",",
"error",
")",
"{",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"signedSnapshot",
",",
"err",
":=",
"tr",
".",
"Snapshot",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"err",
"=",
"tr",
".",
"UpdateTimestamp",
"(",
"signedSnapshot",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tr",
".",
"Timestamp",
".",
"Signed",
".",
"Expires",
"=",
"expires",
"\n",
"tr",
".",
"Timestamp",
".",
"Signed",
".",
"Version",
"++",
"\n",
"signed",
",",
"err",
":=",
"tr",
".",
"Timestamp",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"timestamp",
",",
"err",
":=",
"tr",
".",
"GetBaseRole",
"(",
"data",
".",
"CanonicalTimestampRole",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"signed",
",",
"err",
"=",
"tr",
".",
"sign",
"(",
"signed",
",",
"[",
"]",
"data",
".",
"BaseRole",
"{",
"timestamp",
"}",
",",
"nil",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"tr",
".",
"Timestamp",
".",
"Signatures",
"=",
"signed",
".",
"Signatures",
"\n",
"tr",
".",
"Snapshot",
".",
"Dirty",
"=",
"false",
"// snapshot is dirty until changes have been captured in timestamp",
"\n",
"return",
"signed",
",",
"nil",
"\n",
"}"
] |
// SignTimestamp updates the timestamp based on the current snapshot then signs it
|
[
"SignTimestamp",
"updates",
"the",
"timestamp",
"based",
"on",
"the",
"current",
"snapshot",
"then",
"signs",
"it"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/tuf.go#L1030-L1057
|
train
|
theupdateframework/notary
|
tuf/data/targets.go
|
isValidTargetsStructure
|
func isValidTargetsStructure(t Targets, roleName RoleName) error {
if roleName != CanonicalTargetsRole && !IsDelegation(roleName) {
return ErrInvalidRole{Role: roleName}
}
// even if it's a delegated role, the metadata type is "Targets"
expectedType := TUFTypes[CanonicalTargetsRole]
if t.Type != expectedType {
return ErrInvalidMetadata{
role: roleName, msg: fmt.Sprintf("expected type %s, not %s", expectedType, t.Type)}
}
if t.Version < 1 {
return ErrInvalidMetadata{role: roleName, msg: "version cannot be less than one"}
}
for _, roleObj := range t.Delegations.Roles {
if !IsDelegation(roleObj.Name) || path.Dir(roleObj.Name.String()) != roleName.String() {
return ErrInvalidMetadata{
role: roleName, msg: fmt.Sprintf("delegation role %s invalid", roleObj.Name)}
}
if err := isValidRootRoleStructure(roleName, roleObj.Name, roleObj.RootRole, t.Delegations.Keys); err != nil {
return err
}
}
return nil
}
|
go
|
func isValidTargetsStructure(t Targets, roleName RoleName) error {
if roleName != CanonicalTargetsRole && !IsDelegation(roleName) {
return ErrInvalidRole{Role: roleName}
}
// even if it's a delegated role, the metadata type is "Targets"
expectedType := TUFTypes[CanonicalTargetsRole]
if t.Type != expectedType {
return ErrInvalidMetadata{
role: roleName, msg: fmt.Sprintf("expected type %s, not %s", expectedType, t.Type)}
}
if t.Version < 1 {
return ErrInvalidMetadata{role: roleName, msg: "version cannot be less than one"}
}
for _, roleObj := range t.Delegations.Roles {
if !IsDelegation(roleObj.Name) || path.Dir(roleObj.Name.String()) != roleName.String() {
return ErrInvalidMetadata{
role: roleName, msg: fmt.Sprintf("delegation role %s invalid", roleObj.Name)}
}
if err := isValidRootRoleStructure(roleName, roleObj.Name, roleObj.RootRole, t.Delegations.Keys); err != nil {
return err
}
}
return nil
}
|
[
"func",
"isValidTargetsStructure",
"(",
"t",
"Targets",
",",
"roleName",
"RoleName",
")",
"error",
"{",
"if",
"roleName",
"!=",
"CanonicalTargetsRole",
"&&",
"!",
"IsDelegation",
"(",
"roleName",
")",
"{",
"return",
"ErrInvalidRole",
"{",
"Role",
":",
"roleName",
"}",
"\n",
"}",
"\n\n",
"// even if it's a delegated role, the metadata type is \"Targets\"",
"expectedType",
":=",
"TUFTypes",
"[",
"CanonicalTargetsRole",
"]",
"\n",
"if",
"t",
".",
"Type",
"!=",
"expectedType",
"{",
"return",
"ErrInvalidMetadata",
"{",
"role",
":",
"roleName",
",",
"msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"expectedType",
",",
"t",
".",
"Type",
")",
"}",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"Version",
"<",
"1",
"{",
"return",
"ErrInvalidMetadata",
"{",
"role",
":",
"roleName",
",",
"msg",
":",
"\"",
"\"",
"}",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"roleObj",
":=",
"range",
"t",
".",
"Delegations",
".",
"Roles",
"{",
"if",
"!",
"IsDelegation",
"(",
"roleObj",
".",
"Name",
")",
"||",
"path",
".",
"Dir",
"(",
"roleObj",
".",
"Name",
".",
"String",
"(",
")",
")",
"!=",
"roleName",
".",
"String",
"(",
")",
"{",
"return",
"ErrInvalidMetadata",
"{",
"role",
":",
"roleName",
",",
"msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"roleObj",
".",
"Name",
")",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"isValidRootRoleStructure",
"(",
"roleName",
",",
"roleObj",
".",
"Name",
",",
"roleObj",
".",
"RootRole",
",",
"t",
".",
"Delegations",
".",
"Keys",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// isValidTargetsStructure returns an error, or nil, depending on whether the content of the struct
// is valid for targets metadata. This does not check signatures or expiry, just that
// the metadata content is valid.
|
[
"isValidTargetsStructure",
"returns",
"an",
"error",
"or",
"nil",
"depending",
"on",
"whether",
"the",
"content",
"of",
"the",
"struct",
"is",
"valid",
"for",
"targets",
"metadata",
".",
"This",
"does",
"not",
"check",
"signatures",
"or",
"expiry",
"just",
"that",
"the",
"metadata",
"content",
"is",
"valid",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/targets.go#L29-L55
|
train
|
theupdateframework/notary
|
tuf/data/targets.go
|
NewTargets
|
func NewTargets() *SignedTargets {
return &SignedTargets{
Signatures: make([]Signature, 0),
Signed: Targets{
SignedCommon: SignedCommon{
Type: TUFTypes["targets"],
Version: 0,
Expires: DefaultExpires("targets"),
},
Targets: make(Files),
Delegations: *NewDelegations(),
},
Dirty: true,
}
}
|
go
|
func NewTargets() *SignedTargets {
return &SignedTargets{
Signatures: make([]Signature, 0),
Signed: Targets{
SignedCommon: SignedCommon{
Type: TUFTypes["targets"],
Version: 0,
Expires: DefaultExpires("targets"),
},
Targets: make(Files),
Delegations: *NewDelegations(),
},
Dirty: true,
}
}
|
[
"func",
"NewTargets",
"(",
")",
"*",
"SignedTargets",
"{",
"return",
"&",
"SignedTargets",
"{",
"Signatures",
":",
"make",
"(",
"[",
"]",
"Signature",
",",
"0",
")",
",",
"Signed",
":",
"Targets",
"{",
"SignedCommon",
":",
"SignedCommon",
"{",
"Type",
":",
"TUFTypes",
"[",
"\"",
"\"",
"]",
",",
"Version",
":",
"0",
",",
"Expires",
":",
"DefaultExpires",
"(",
"\"",
"\"",
")",
",",
"}",
",",
"Targets",
":",
"make",
"(",
"Files",
")",
",",
"Delegations",
":",
"*",
"NewDelegations",
"(",
")",
",",
"}",
",",
"Dirty",
":",
"true",
",",
"}",
"\n",
"}"
] |
// NewTargets initializes a new empty SignedTargets object
|
[
"NewTargets",
"initializes",
"a",
"new",
"empty",
"SignedTargets",
"object"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/targets.go#L58-L72
|
train
|
theupdateframework/notary
|
tuf/data/targets.go
|
GetMeta
|
func (t SignedTargets) GetMeta(path string) *FileMeta {
for p, meta := range t.Signed.Targets {
if p == path {
return &meta
}
}
return nil
}
|
go
|
func (t SignedTargets) GetMeta(path string) *FileMeta {
for p, meta := range t.Signed.Targets {
if p == path {
return &meta
}
}
return nil
}
|
[
"func",
"(",
"t",
"SignedTargets",
")",
"GetMeta",
"(",
"path",
"string",
")",
"*",
"FileMeta",
"{",
"for",
"p",
",",
"meta",
":=",
"range",
"t",
".",
"Signed",
".",
"Targets",
"{",
"if",
"p",
"==",
"path",
"{",
"return",
"&",
"meta",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// GetMeta attempts to find the targets entry for the path. It
// will return nil in the case of the target not being found.
|
[
"GetMeta",
"attempts",
"to",
"find",
"the",
"targets",
"entry",
"for",
"the",
"path",
".",
"It",
"will",
"return",
"nil",
"in",
"the",
"case",
"of",
"the",
"target",
"not",
"being",
"found",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/targets.go#L76-L83
|
train
|
theupdateframework/notary
|
tuf/data/targets.go
|
GetValidDelegations
|
func (t SignedTargets) GetValidDelegations(parent DelegationRole) []DelegationRole {
roles := t.buildDelegationRoles()
result := []DelegationRole{}
for _, r := range roles {
validRole, err := parent.Restrict(r)
if err != nil {
continue
}
result = append(result, validRole)
}
return result
}
|
go
|
func (t SignedTargets) GetValidDelegations(parent DelegationRole) []DelegationRole {
roles := t.buildDelegationRoles()
result := []DelegationRole{}
for _, r := range roles {
validRole, err := parent.Restrict(r)
if err != nil {
continue
}
result = append(result, validRole)
}
return result
}
|
[
"func",
"(",
"t",
"SignedTargets",
")",
"GetValidDelegations",
"(",
"parent",
"DelegationRole",
")",
"[",
"]",
"DelegationRole",
"{",
"roles",
":=",
"t",
".",
"buildDelegationRoles",
"(",
")",
"\n",
"result",
":=",
"[",
"]",
"DelegationRole",
"{",
"}",
"\n",
"for",
"_",
",",
"r",
":=",
"range",
"roles",
"{",
"validRole",
",",
"err",
":=",
"parent",
".",
"Restrict",
"(",
"r",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"result",
"=",
"append",
"(",
"result",
",",
"validRole",
")",
"\n",
"}",
"\n",
"return",
"result",
"\n",
"}"
] |
// GetValidDelegations filters the delegation roles specified in the signed targets, and
// only returns roles that are direct children and restricts their paths
|
[
"GetValidDelegations",
"filters",
"the",
"delegation",
"roles",
"specified",
"in",
"the",
"signed",
"targets",
"and",
"only",
"returns",
"roles",
"that",
"are",
"direct",
"children",
"and",
"restricts",
"their",
"paths"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/targets.go#L87-L98
|
train
|
theupdateframework/notary
|
tuf/data/targets.go
|
BuildDelegationRole
|
func (t *SignedTargets) BuildDelegationRole(roleName RoleName) (DelegationRole, error) {
for _, role := range t.Signed.Delegations.Roles {
if role.Name == roleName {
pubKeys := make(map[string]PublicKey)
for _, keyID := range role.KeyIDs {
pubKey, ok := t.Signed.Delegations.Keys[keyID]
if !ok {
// Couldn't retrieve all keys, so stop walking and return invalid role
return DelegationRole{}, ErrInvalidRole{
Role: roleName,
Reason: "role lists unknown key " + keyID + " as a signing key",
}
}
pubKeys[keyID] = pubKey
}
return DelegationRole{
BaseRole: BaseRole{
Name: role.Name,
Keys: pubKeys,
Threshold: role.Threshold,
},
Paths: role.Paths,
}, nil
}
}
return DelegationRole{}, ErrNoSuchRole{Role: roleName}
}
|
go
|
func (t *SignedTargets) BuildDelegationRole(roleName RoleName) (DelegationRole, error) {
for _, role := range t.Signed.Delegations.Roles {
if role.Name == roleName {
pubKeys := make(map[string]PublicKey)
for _, keyID := range role.KeyIDs {
pubKey, ok := t.Signed.Delegations.Keys[keyID]
if !ok {
// Couldn't retrieve all keys, so stop walking and return invalid role
return DelegationRole{}, ErrInvalidRole{
Role: roleName,
Reason: "role lists unknown key " + keyID + " as a signing key",
}
}
pubKeys[keyID] = pubKey
}
return DelegationRole{
BaseRole: BaseRole{
Name: role.Name,
Keys: pubKeys,
Threshold: role.Threshold,
},
Paths: role.Paths,
}, nil
}
}
return DelegationRole{}, ErrNoSuchRole{Role: roleName}
}
|
[
"func",
"(",
"t",
"*",
"SignedTargets",
")",
"BuildDelegationRole",
"(",
"roleName",
"RoleName",
")",
"(",
"DelegationRole",
",",
"error",
")",
"{",
"for",
"_",
",",
"role",
":=",
"range",
"t",
".",
"Signed",
".",
"Delegations",
".",
"Roles",
"{",
"if",
"role",
".",
"Name",
"==",
"roleName",
"{",
"pubKeys",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"PublicKey",
")",
"\n",
"for",
"_",
",",
"keyID",
":=",
"range",
"role",
".",
"KeyIDs",
"{",
"pubKey",
",",
"ok",
":=",
"t",
".",
"Signed",
".",
"Delegations",
".",
"Keys",
"[",
"keyID",
"]",
"\n",
"if",
"!",
"ok",
"{",
"// Couldn't retrieve all keys, so stop walking and return invalid role",
"return",
"DelegationRole",
"{",
"}",
",",
"ErrInvalidRole",
"{",
"Role",
":",
"roleName",
",",
"Reason",
":",
"\"",
"\"",
"+",
"keyID",
"+",
"\"",
"\"",
",",
"}",
"\n",
"}",
"\n",
"pubKeys",
"[",
"keyID",
"]",
"=",
"pubKey",
"\n",
"}",
"\n",
"return",
"DelegationRole",
"{",
"BaseRole",
":",
"BaseRole",
"{",
"Name",
":",
"role",
".",
"Name",
",",
"Keys",
":",
"pubKeys",
",",
"Threshold",
":",
"role",
".",
"Threshold",
",",
"}",
",",
"Paths",
":",
"role",
".",
"Paths",
",",
"}",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"DelegationRole",
"{",
"}",
",",
"ErrNoSuchRole",
"{",
"Role",
":",
"roleName",
"}",
"\n",
"}"
] |
// BuildDelegationRole returns a copy of a DelegationRole using the information in this SignedTargets for the specified role name.
// Will error for invalid role name or key metadata within this SignedTargets. Path data is not validated.
|
[
"BuildDelegationRole",
"returns",
"a",
"copy",
"of",
"a",
"DelegationRole",
"using",
"the",
"information",
"in",
"this",
"SignedTargets",
"for",
"the",
"specified",
"role",
"name",
".",
"Will",
"error",
"for",
"invalid",
"role",
"name",
"or",
"key",
"metadata",
"within",
"this",
"SignedTargets",
".",
"Path",
"data",
"is",
"not",
"validated",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/targets.go#L102-L128
|
train
|
theupdateframework/notary
|
tuf/data/targets.go
|
buildDelegationRoles
|
func (t SignedTargets) buildDelegationRoles() []DelegationRole {
var roles []DelegationRole
for _, roleData := range t.Signed.Delegations.Roles {
delgRole, err := t.BuildDelegationRole(roleData.Name)
if err != nil {
continue
}
roles = append(roles, delgRole)
}
return roles
}
|
go
|
func (t SignedTargets) buildDelegationRoles() []DelegationRole {
var roles []DelegationRole
for _, roleData := range t.Signed.Delegations.Roles {
delgRole, err := t.BuildDelegationRole(roleData.Name)
if err != nil {
continue
}
roles = append(roles, delgRole)
}
return roles
}
|
[
"func",
"(",
"t",
"SignedTargets",
")",
"buildDelegationRoles",
"(",
")",
"[",
"]",
"DelegationRole",
"{",
"var",
"roles",
"[",
"]",
"DelegationRole",
"\n",
"for",
"_",
",",
"roleData",
":=",
"range",
"t",
".",
"Signed",
".",
"Delegations",
".",
"Roles",
"{",
"delgRole",
",",
"err",
":=",
"t",
".",
"BuildDelegationRole",
"(",
"roleData",
".",
"Name",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"roles",
"=",
"append",
"(",
"roles",
",",
"delgRole",
")",
"\n",
"}",
"\n",
"return",
"roles",
"\n",
"}"
] |
// helper function to create DelegationRole structures from all delegations in a SignedTargets,
// these delegations are read directly from the SignedTargets and not modified or validated
|
[
"helper",
"function",
"to",
"create",
"DelegationRole",
"structures",
"from",
"all",
"delegations",
"in",
"a",
"SignedTargets",
"these",
"delegations",
"are",
"read",
"directly",
"from",
"the",
"SignedTargets",
"and",
"not",
"modified",
"or",
"validated"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/targets.go#L132-L142
|
train
|
theupdateframework/notary
|
tuf/data/targets.go
|
AddTarget
|
func (t *SignedTargets) AddTarget(path string, meta FileMeta) {
t.Signed.Targets[path] = meta
t.Dirty = true
}
|
go
|
func (t *SignedTargets) AddTarget(path string, meta FileMeta) {
t.Signed.Targets[path] = meta
t.Dirty = true
}
|
[
"func",
"(",
"t",
"*",
"SignedTargets",
")",
"AddTarget",
"(",
"path",
"string",
",",
"meta",
"FileMeta",
")",
"{",
"t",
".",
"Signed",
".",
"Targets",
"[",
"path",
"]",
"=",
"meta",
"\n",
"t",
".",
"Dirty",
"=",
"true",
"\n",
"}"
] |
// AddTarget adds or updates the meta for the given path
|
[
"AddTarget",
"adds",
"or",
"updates",
"the",
"meta",
"for",
"the",
"given",
"path"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/targets.go#L145-L148
|
train
|
theupdateframework/notary
|
tuf/data/targets.go
|
AddDelegation
|
func (t *SignedTargets) AddDelegation(role *Role, keys []*PublicKey) error {
return errors.New("Not Implemented")
}
|
go
|
func (t *SignedTargets) AddDelegation(role *Role, keys []*PublicKey) error {
return errors.New("Not Implemented")
}
|
[
"func",
"(",
"t",
"*",
"SignedTargets",
")",
"AddDelegation",
"(",
"role",
"*",
"Role",
",",
"keys",
"[",
"]",
"*",
"PublicKey",
")",
"error",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// AddDelegation will add a new delegated role with the given keys,
// ensuring the keys either already exist, or are added to the map
// of delegation keys
|
[
"AddDelegation",
"will",
"add",
"a",
"new",
"delegated",
"role",
"with",
"the",
"given",
"keys",
"ensuring",
"the",
"keys",
"either",
"already",
"exist",
"or",
"are",
"added",
"to",
"the",
"map",
"of",
"delegation",
"keys"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/targets.go#L153-L155
|
train
|
theupdateframework/notary
|
tuf/data/targets.go
|
MarshalJSON
|
func (t *SignedTargets) MarshalJSON() ([]byte, error) {
signed, err := t.ToSigned()
if err != nil {
return nil, err
}
return defaultSerializer.Marshal(signed)
}
|
go
|
func (t *SignedTargets) MarshalJSON() ([]byte, error) {
signed, err := t.ToSigned()
if err != nil {
return nil, err
}
return defaultSerializer.Marshal(signed)
}
|
[
"func",
"(",
"t",
"*",
"SignedTargets",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"signed",
",",
"err",
":=",
"t",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"defaultSerializer",
".",
"Marshal",
"(",
"signed",
")",
"\n",
"}"
] |
// MarshalJSON returns the serialized form of SignedTargets as bytes
|
[
"MarshalJSON",
"returns",
"the",
"serialized",
"form",
"of",
"SignedTargets",
"as",
"bytes"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/targets.go#L177-L183
|
train
|
theupdateframework/notary
|
tuf/builder.go
|
ChecksumKnown
|
func (c ConsistentInfo) ChecksumKnown() bool {
// empty hash, no size : this is the zero value
return len(c.fileMeta.Hashes) > 0 || c.fileMeta.Length != 0
}
|
go
|
func (c ConsistentInfo) ChecksumKnown() bool {
// empty hash, no size : this is the zero value
return len(c.fileMeta.Hashes) > 0 || c.fileMeta.Length != 0
}
|
[
"func",
"(",
"c",
"ConsistentInfo",
")",
"ChecksumKnown",
"(",
")",
"bool",
"{",
"// empty hash, no size : this is the zero value",
"return",
"len",
"(",
"c",
".",
"fileMeta",
".",
"Hashes",
")",
">",
"0",
"||",
"c",
".",
"fileMeta",
".",
"Length",
"!=",
"0",
"\n",
"}"
] |
// ChecksumKnown determines whether or not we know enough to provide a size and
// consistent name
|
[
"ChecksumKnown",
"determines",
"whether",
"or",
"not",
"we",
"know",
"enough",
"to",
"provide",
"a",
"size",
"and",
"consistent",
"name"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/builder.go#L37-L40
|
train
|
theupdateframework/notary
|
tuf/builder.go
|
NewRepoBuilder
|
func NewRepoBuilder(gun data.GUN, cs signed.CryptoService, trustpin trustpinning.TrustPinConfig) RepoBuilder {
return NewBuilderFromRepo(gun, NewRepo(cs), trustpin)
}
|
go
|
func NewRepoBuilder(gun data.GUN, cs signed.CryptoService, trustpin trustpinning.TrustPinConfig) RepoBuilder {
return NewBuilderFromRepo(gun, NewRepo(cs), trustpin)
}
|
[
"func",
"NewRepoBuilder",
"(",
"gun",
"data",
".",
"GUN",
",",
"cs",
"signed",
".",
"CryptoService",
",",
"trustpin",
"trustpinning",
".",
"TrustPinConfig",
")",
"RepoBuilder",
"{",
"return",
"NewBuilderFromRepo",
"(",
"gun",
",",
"NewRepo",
"(",
"cs",
")",
",",
"trustpin",
")",
"\n",
"}"
] |
// NewRepoBuilder is the only way to get a pre-built RepoBuilder
|
[
"NewRepoBuilder",
"is",
"the",
"only",
"way",
"to",
"get",
"a",
"pre",
"-",
"built",
"RepoBuilder"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/builder.go#L100-L102
|
train
|
theupdateframework/notary
|
tuf/builder.go
|
NewBuilderFromRepo
|
func NewBuilderFromRepo(gun data.GUN, repo *Repo, trustpin trustpinning.TrustPinConfig) RepoBuilder {
return &repoBuilderWrapper{
RepoBuilder: &repoBuilder{
repo: repo,
invalidRoles: NewRepo(nil),
gun: gun,
trustpin: trustpin,
loadedNotChecksummed: make(map[data.RoleName][]byte),
},
}
}
|
go
|
func NewBuilderFromRepo(gun data.GUN, repo *Repo, trustpin trustpinning.TrustPinConfig) RepoBuilder {
return &repoBuilderWrapper{
RepoBuilder: &repoBuilder{
repo: repo,
invalidRoles: NewRepo(nil),
gun: gun,
trustpin: trustpin,
loadedNotChecksummed: make(map[data.RoleName][]byte),
},
}
}
|
[
"func",
"NewBuilderFromRepo",
"(",
"gun",
"data",
".",
"GUN",
",",
"repo",
"*",
"Repo",
",",
"trustpin",
"trustpinning",
".",
"TrustPinConfig",
")",
"RepoBuilder",
"{",
"return",
"&",
"repoBuilderWrapper",
"{",
"RepoBuilder",
":",
"&",
"repoBuilder",
"{",
"repo",
":",
"repo",
",",
"invalidRoles",
":",
"NewRepo",
"(",
"nil",
")",
",",
"gun",
":",
"gun",
",",
"trustpin",
":",
"trustpin",
",",
"loadedNotChecksummed",
":",
"make",
"(",
"map",
"[",
"data",
".",
"RoleName",
"]",
"[",
"]",
"byte",
")",
",",
"}",
",",
"}",
"\n",
"}"
] |
// NewBuilderFromRepo allows us to bootstrap a builder given existing repo data.
// YOU PROBABLY SHOULDN'T BE USING THIS OUTSIDE OF TESTING CODE!!!
|
[
"NewBuilderFromRepo",
"allows",
"us",
"to",
"bootstrap",
"a",
"builder",
"given",
"existing",
"repo",
"data",
".",
"YOU",
"PROBABLY",
"SHOULDN",
"T",
"BE",
"USING",
"THIS",
"OUTSIDE",
"OF",
"TESTING",
"CODE!!!"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/builder.go#L106-L116
|
train
|
theupdateframework/notary
|
tuf/builder.go
|
IsLoaded
|
func (rb *repoBuilder) IsLoaded(roleName data.RoleName) bool {
switch roleName {
case data.CanonicalRootRole:
return rb.repo.Root != nil
case data.CanonicalSnapshotRole:
return rb.repo.Snapshot != nil
case data.CanonicalTimestampRole:
return rb.repo.Timestamp != nil
default:
return rb.repo.Targets[roleName] != nil
}
}
|
go
|
func (rb *repoBuilder) IsLoaded(roleName data.RoleName) bool {
switch roleName {
case data.CanonicalRootRole:
return rb.repo.Root != nil
case data.CanonicalSnapshotRole:
return rb.repo.Snapshot != nil
case data.CanonicalTimestampRole:
return rb.repo.Timestamp != nil
default:
return rb.repo.Targets[roleName] != nil
}
}
|
[
"func",
"(",
"rb",
"*",
"repoBuilder",
")",
"IsLoaded",
"(",
"roleName",
"data",
".",
"RoleName",
")",
"bool",
"{",
"switch",
"roleName",
"{",
"case",
"data",
".",
"CanonicalRootRole",
":",
"return",
"rb",
".",
"repo",
".",
"Root",
"!=",
"nil",
"\n",
"case",
"data",
".",
"CanonicalSnapshotRole",
":",
"return",
"rb",
".",
"repo",
".",
"Snapshot",
"!=",
"nil",
"\n",
"case",
"data",
".",
"CanonicalTimestampRole",
":",
"return",
"rb",
".",
"repo",
".",
"Timestamp",
"!=",
"nil",
"\n",
"default",
":",
"return",
"rb",
".",
"repo",
".",
"Targets",
"[",
"roleName",
"]",
"!=",
"nil",
"\n",
"}",
"\n",
"}"
] |
// IsLoaded returns whether a particular role has already been loaded
|
[
"IsLoaded",
"returns",
"whether",
"a",
"particular",
"role",
"has",
"already",
"been",
"loaded"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/builder.go#L187-L198
|
train
|
theupdateframework/notary
|
tuf/builder.go
|
LoadRootForUpdate
|
func (rb *repoBuilder) LoadRootForUpdate(content []byte, minVersion int, isFinal bool) error {
if err := rb.loadOptions(data.CanonicalRootRole, content, minVersion, !isFinal, !isFinal, true); err != nil {
return err
}
if !isFinal {
rb.prevRoot = rb.repo.Root
}
return nil
}
|
go
|
func (rb *repoBuilder) LoadRootForUpdate(content []byte, minVersion int, isFinal bool) error {
if err := rb.loadOptions(data.CanonicalRootRole, content, minVersion, !isFinal, !isFinal, true); err != nil {
return err
}
if !isFinal {
rb.prevRoot = rb.repo.Root
}
return nil
}
|
[
"func",
"(",
"rb",
"*",
"repoBuilder",
")",
"LoadRootForUpdate",
"(",
"content",
"[",
"]",
"byte",
",",
"minVersion",
"int",
",",
"isFinal",
"bool",
")",
"error",
"{",
"if",
"err",
":=",
"rb",
".",
"loadOptions",
"(",
"data",
".",
"CanonicalRootRole",
",",
"content",
",",
"minVersion",
",",
"!",
"isFinal",
",",
"!",
"isFinal",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"!",
"isFinal",
"{",
"rb",
".",
"prevRoot",
"=",
"rb",
".",
"repo",
".",
"Root",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// LoadRootForUpdate adds additional flags for updating the root.json file
|
[
"LoadRootForUpdate",
"adds",
"additional",
"flags",
"for",
"updating",
"the",
"root",
".",
"json",
"file"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/builder.go#L253-L261
|
train
|
theupdateframework/notary
|
tuf/builder.go
|
loadOptions
|
func (rb *repoBuilder) loadOptions(roleName data.RoleName, content []byte, minVersion int, allowExpired, skipChecksum, allowLoaded bool) error {
if !data.ValidRole(roleName) {
return ErrInvalidBuilderInput{msg: fmt.Sprintf("%s is an invalid role", roleName)}
}
if !allowLoaded && rb.IsLoaded(roleName) {
return ErrInvalidBuilderInput{msg: fmt.Sprintf("%s has already been loaded", roleName)}
}
var err error
switch roleName {
case data.CanonicalRootRole:
break
case data.CanonicalTimestampRole, data.CanonicalSnapshotRole, data.CanonicalTargetsRole:
err = rb.checkPrereqsLoaded([]data.RoleName{data.CanonicalRootRole})
default: // delegations
err = rb.checkPrereqsLoaded([]data.RoleName{data.CanonicalRootRole, data.CanonicalTargetsRole})
}
if err != nil {
return err
}
switch roleName {
case data.CanonicalRootRole:
return rb.loadRoot(content, minVersion, allowExpired, skipChecksum)
case data.CanonicalSnapshotRole:
return rb.loadSnapshot(content, minVersion, allowExpired)
case data.CanonicalTimestampRole:
return rb.loadTimestamp(content, minVersion, allowExpired)
case data.CanonicalTargetsRole:
return rb.loadTargets(content, minVersion, allowExpired)
default:
return rb.loadDelegation(roleName, content, minVersion, allowExpired)
}
}
|
go
|
func (rb *repoBuilder) loadOptions(roleName data.RoleName, content []byte, minVersion int, allowExpired, skipChecksum, allowLoaded bool) error {
if !data.ValidRole(roleName) {
return ErrInvalidBuilderInput{msg: fmt.Sprintf("%s is an invalid role", roleName)}
}
if !allowLoaded && rb.IsLoaded(roleName) {
return ErrInvalidBuilderInput{msg: fmt.Sprintf("%s has already been loaded", roleName)}
}
var err error
switch roleName {
case data.CanonicalRootRole:
break
case data.CanonicalTimestampRole, data.CanonicalSnapshotRole, data.CanonicalTargetsRole:
err = rb.checkPrereqsLoaded([]data.RoleName{data.CanonicalRootRole})
default: // delegations
err = rb.checkPrereqsLoaded([]data.RoleName{data.CanonicalRootRole, data.CanonicalTargetsRole})
}
if err != nil {
return err
}
switch roleName {
case data.CanonicalRootRole:
return rb.loadRoot(content, minVersion, allowExpired, skipChecksum)
case data.CanonicalSnapshotRole:
return rb.loadSnapshot(content, minVersion, allowExpired)
case data.CanonicalTimestampRole:
return rb.loadTimestamp(content, minVersion, allowExpired)
case data.CanonicalTargetsRole:
return rb.loadTargets(content, minVersion, allowExpired)
default:
return rb.loadDelegation(roleName, content, minVersion, allowExpired)
}
}
|
[
"func",
"(",
"rb",
"*",
"repoBuilder",
")",
"loadOptions",
"(",
"roleName",
"data",
".",
"RoleName",
",",
"content",
"[",
"]",
"byte",
",",
"minVersion",
"int",
",",
"allowExpired",
",",
"skipChecksum",
",",
"allowLoaded",
"bool",
")",
"error",
"{",
"if",
"!",
"data",
".",
"ValidRole",
"(",
"roleName",
")",
"{",
"return",
"ErrInvalidBuilderInput",
"{",
"msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"roleName",
")",
"}",
"\n",
"}",
"\n\n",
"if",
"!",
"allowLoaded",
"&&",
"rb",
".",
"IsLoaded",
"(",
"roleName",
")",
"{",
"return",
"ErrInvalidBuilderInput",
"{",
"msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"roleName",
")",
"}",
"\n",
"}",
"\n\n",
"var",
"err",
"error",
"\n",
"switch",
"roleName",
"{",
"case",
"data",
".",
"CanonicalRootRole",
":",
"break",
"\n",
"case",
"data",
".",
"CanonicalTimestampRole",
",",
"data",
".",
"CanonicalSnapshotRole",
",",
"data",
".",
"CanonicalTargetsRole",
":",
"err",
"=",
"rb",
".",
"checkPrereqsLoaded",
"(",
"[",
"]",
"data",
".",
"RoleName",
"{",
"data",
".",
"CanonicalRootRole",
"}",
")",
"\n",
"default",
":",
"// delegations",
"err",
"=",
"rb",
".",
"checkPrereqsLoaded",
"(",
"[",
"]",
"data",
".",
"RoleName",
"{",
"data",
".",
"CanonicalRootRole",
",",
"data",
".",
"CanonicalTargetsRole",
"}",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"switch",
"roleName",
"{",
"case",
"data",
".",
"CanonicalRootRole",
":",
"return",
"rb",
".",
"loadRoot",
"(",
"content",
",",
"minVersion",
",",
"allowExpired",
",",
"skipChecksum",
")",
"\n",
"case",
"data",
".",
"CanonicalSnapshotRole",
":",
"return",
"rb",
".",
"loadSnapshot",
"(",
"content",
",",
"minVersion",
",",
"allowExpired",
")",
"\n",
"case",
"data",
".",
"CanonicalTimestampRole",
":",
"return",
"rb",
".",
"loadTimestamp",
"(",
"content",
",",
"minVersion",
",",
"allowExpired",
")",
"\n",
"case",
"data",
".",
"CanonicalTargetsRole",
":",
"return",
"rb",
".",
"loadTargets",
"(",
"content",
",",
"minVersion",
",",
"allowExpired",
")",
"\n",
"default",
":",
"return",
"rb",
".",
"loadDelegation",
"(",
"roleName",
",",
"content",
",",
"minVersion",
",",
"allowExpired",
")",
"\n",
"}",
"\n",
"}"
] |
// loadOptions adds additional flags that should only be used for updating the root.json
|
[
"loadOptions",
"adds",
"additional",
"flags",
"that",
"should",
"only",
"be",
"used",
"for",
"updating",
"the",
"root",
".",
"json"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/builder.go#L264-L298
|
train
|
theupdateframework/notary
|
tuf/builder.go
|
loadRoot
|
func (rb *repoBuilder) loadRoot(content []byte, minVersion int, allowExpired, skipChecksum bool) error {
roleName := data.CanonicalRootRole
signedObj, err := rb.bytesToSigned(content, data.CanonicalRootRole, skipChecksum)
if err != nil {
return err
}
// ValidateRoot validates against the previous root's role, as well as validates that the root
// itself is self-consistent with its own signatures and thresholds.
// This assumes that ValidateRoot calls data.RootFromSigned, which validates
// the metadata, rather than just unmarshalling signedObject into a SignedRoot object itself.
signedRoot, err := trustpinning.ValidateRoot(rb.prevRoot, signedObj, rb.gun, rb.trustpin)
if err != nil {
return err
}
if err := signed.VerifyVersion(&(signedRoot.Signed.SignedCommon), minVersion); err != nil {
return err
}
if !allowExpired { // check must go at the end because all other validation should pass
if err := signed.VerifyExpiry(&(signedRoot.Signed.SignedCommon), roleName); err != nil {
return err
}
}
rootRole, err := signedRoot.BuildBaseRole(data.CanonicalRootRole)
if err != nil { // this should never happen since the root has been validated
return err
}
rb.repo.Root = signedRoot
rb.repo.originalRootRole = rootRole
return nil
}
|
go
|
func (rb *repoBuilder) loadRoot(content []byte, minVersion int, allowExpired, skipChecksum bool) error {
roleName := data.CanonicalRootRole
signedObj, err := rb.bytesToSigned(content, data.CanonicalRootRole, skipChecksum)
if err != nil {
return err
}
// ValidateRoot validates against the previous root's role, as well as validates that the root
// itself is self-consistent with its own signatures and thresholds.
// This assumes that ValidateRoot calls data.RootFromSigned, which validates
// the metadata, rather than just unmarshalling signedObject into a SignedRoot object itself.
signedRoot, err := trustpinning.ValidateRoot(rb.prevRoot, signedObj, rb.gun, rb.trustpin)
if err != nil {
return err
}
if err := signed.VerifyVersion(&(signedRoot.Signed.SignedCommon), minVersion); err != nil {
return err
}
if !allowExpired { // check must go at the end because all other validation should pass
if err := signed.VerifyExpiry(&(signedRoot.Signed.SignedCommon), roleName); err != nil {
return err
}
}
rootRole, err := signedRoot.BuildBaseRole(data.CanonicalRootRole)
if err != nil { // this should never happen since the root has been validated
return err
}
rb.repo.Root = signedRoot
rb.repo.originalRootRole = rootRole
return nil
}
|
[
"func",
"(",
"rb",
"*",
"repoBuilder",
")",
"loadRoot",
"(",
"content",
"[",
"]",
"byte",
",",
"minVersion",
"int",
",",
"allowExpired",
",",
"skipChecksum",
"bool",
")",
"error",
"{",
"roleName",
":=",
"data",
".",
"CanonicalRootRole",
"\n\n",
"signedObj",
",",
"err",
":=",
"rb",
".",
"bytesToSigned",
"(",
"content",
",",
"data",
".",
"CanonicalRootRole",
",",
"skipChecksum",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"// ValidateRoot validates against the previous root's role, as well as validates that the root",
"// itself is self-consistent with its own signatures and thresholds.",
"// This assumes that ValidateRoot calls data.RootFromSigned, which validates",
"// the metadata, rather than just unmarshalling signedObject into a SignedRoot object itself.",
"signedRoot",
",",
"err",
":=",
"trustpinning",
".",
"ValidateRoot",
"(",
"rb",
".",
"prevRoot",
",",
"signedObj",
",",
"rb",
".",
"gun",
",",
"rb",
".",
"trustpin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"signed",
".",
"VerifyVersion",
"(",
"&",
"(",
"signedRoot",
".",
"Signed",
".",
"SignedCommon",
")",
",",
"minVersion",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"!",
"allowExpired",
"{",
"// check must go at the end because all other validation should pass",
"if",
"err",
":=",
"signed",
".",
"VerifyExpiry",
"(",
"&",
"(",
"signedRoot",
".",
"Signed",
".",
"SignedCommon",
")",
",",
"roleName",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"rootRole",
",",
"err",
":=",
"signedRoot",
".",
"BuildBaseRole",
"(",
"data",
".",
"CanonicalRootRole",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"// this should never happen since the root has been validated",
"return",
"err",
"\n",
"}",
"\n",
"rb",
".",
"repo",
".",
"Root",
"=",
"signedRoot",
"\n",
"rb",
".",
"repo",
".",
"originalRootRole",
"=",
"rootRole",
"\n",
"return",
"nil",
"\n",
"}"
] |
// loadRoot loads a root if one has not been loaded
|
[
"loadRoot",
"loads",
"a",
"root",
"if",
"one",
"has",
"not",
"been",
"loaded"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/builder.go#L431-L464
|
train
|
theupdateframework/notary
|
server/storage/sql_models.go
|
CreateTUFTable
|
func CreateTUFTable(db gorm.DB) error {
// TODO: gorm
query := db.AutoMigrate(&TUFFile{})
if query.Error != nil {
return query.Error
}
query = db.Model(&TUFFile{}).AddUniqueIndex(
"idx_gun", "gun", "role", "version")
return query.Error
}
|
go
|
func CreateTUFTable(db gorm.DB) error {
// TODO: gorm
query := db.AutoMigrate(&TUFFile{})
if query.Error != nil {
return query.Error
}
query = db.Model(&TUFFile{}).AddUniqueIndex(
"idx_gun", "gun", "role", "version")
return query.Error
}
|
[
"func",
"CreateTUFTable",
"(",
"db",
"gorm",
".",
"DB",
")",
"error",
"{",
"// TODO: gorm",
"query",
":=",
"db",
".",
"AutoMigrate",
"(",
"&",
"TUFFile",
"{",
"}",
")",
"\n",
"if",
"query",
".",
"Error",
"!=",
"nil",
"{",
"return",
"query",
".",
"Error",
"\n",
"}",
"\n",
"query",
"=",
"db",
".",
"Model",
"(",
"&",
"TUFFile",
"{",
"}",
")",
".",
"AddUniqueIndex",
"(",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"return",
"query",
".",
"Error",
"\n",
"}"
] |
// CreateTUFTable creates the DB table for TUFFile
|
[
"CreateTUFTable",
"creates",
"the",
"DB",
"table",
"for",
"TUFFile"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/sql_models.go#L51-L60
|
train
|
theupdateframework/notary
|
server/storage/sql_models.go
|
CreateChangefeedTable
|
func CreateChangefeedTable(db gorm.DB) error {
query := db.AutoMigrate(&SQLChange{})
return query.Error
}
|
go
|
func CreateChangefeedTable(db gorm.DB) error {
query := db.AutoMigrate(&SQLChange{})
return query.Error
}
|
[
"func",
"CreateChangefeedTable",
"(",
"db",
"gorm",
".",
"DB",
")",
"error",
"{",
"query",
":=",
"db",
".",
"AutoMigrate",
"(",
"&",
"SQLChange",
"{",
"}",
")",
"\n",
"return",
"query",
".",
"Error",
"\n",
"}"
] |
// CreateChangefeedTable creates the DB table for Changefeed
|
[
"CreateChangefeedTable",
"creates",
"the",
"DB",
"table",
"for",
"Changefeed"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/sql_models.go#L63-L66
|
train
|
theupdateframework/notary
|
server/server.go
|
Run
|
func Run(ctx context.Context, conf Config) error {
tcpAddr, err := net.ResolveTCPAddr("tcp", conf.Addr)
if err != nil {
return err
}
var lsnr net.Listener
lsnr, err = net.ListenTCP("tcp", tcpAddr)
if err != nil {
return err
}
if conf.TLSConfig != nil {
logrus.Info("Enabling TLS")
lsnr = tls.NewListener(lsnr, conf.TLSConfig)
}
var ac auth.AccessController
if conf.AuthMethod == "token" {
authOptions, ok := conf.AuthOpts.(map[string]interface{})
if !ok {
return fmt.Errorf("auth.options must be a map[string]interface{}")
}
ac, err = auth.GetAccessController(conf.AuthMethod, authOptions)
if err != nil {
return err
}
}
svr := http.Server{
Addr: conf.Addr,
Handler: RootHandler(
ctx, ac, conf.Trust,
conf.ConsistentCacheControlConfig, conf.CurrentCacheControlConfig,
conf.RepoPrefixes),
}
logrus.Info("Starting on ", conf.Addr)
err = svr.Serve(lsnr)
return err
}
|
go
|
func Run(ctx context.Context, conf Config) error {
tcpAddr, err := net.ResolveTCPAddr("tcp", conf.Addr)
if err != nil {
return err
}
var lsnr net.Listener
lsnr, err = net.ListenTCP("tcp", tcpAddr)
if err != nil {
return err
}
if conf.TLSConfig != nil {
logrus.Info("Enabling TLS")
lsnr = tls.NewListener(lsnr, conf.TLSConfig)
}
var ac auth.AccessController
if conf.AuthMethod == "token" {
authOptions, ok := conf.AuthOpts.(map[string]interface{})
if !ok {
return fmt.Errorf("auth.options must be a map[string]interface{}")
}
ac, err = auth.GetAccessController(conf.AuthMethod, authOptions)
if err != nil {
return err
}
}
svr := http.Server{
Addr: conf.Addr,
Handler: RootHandler(
ctx, ac, conf.Trust,
conf.ConsistentCacheControlConfig, conf.CurrentCacheControlConfig,
conf.RepoPrefixes),
}
logrus.Info("Starting on ", conf.Addr)
err = svr.Serve(lsnr)
return err
}
|
[
"func",
"Run",
"(",
"ctx",
"context",
".",
"Context",
",",
"conf",
"Config",
")",
"error",
"{",
"tcpAddr",
",",
"err",
":=",
"net",
".",
"ResolveTCPAddr",
"(",
"\"",
"\"",
",",
"conf",
".",
"Addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"var",
"lsnr",
"net",
".",
"Listener",
"\n",
"lsnr",
",",
"err",
"=",
"net",
".",
"ListenTCP",
"(",
"\"",
"\"",
",",
"tcpAddr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"conf",
".",
"TLSConfig",
"!=",
"nil",
"{",
"logrus",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"lsnr",
"=",
"tls",
".",
"NewListener",
"(",
"lsnr",
",",
"conf",
".",
"TLSConfig",
")",
"\n",
"}",
"\n\n",
"var",
"ac",
"auth",
".",
"AccessController",
"\n",
"if",
"conf",
".",
"AuthMethod",
"==",
"\"",
"\"",
"{",
"authOptions",
",",
"ok",
":=",
"conf",
".",
"AuthOpts",
".",
"(",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ac",
",",
"err",
"=",
"auth",
".",
"GetAccessController",
"(",
"conf",
".",
"AuthMethod",
",",
"authOptions",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"svr",
":=",
"http",
".",
"Server",
"{",
"Addr",
":",
"conf",
".",
"Addr",
",",
"Handler",
":",
"RootHandler",
"(",
"ctx",
",",
"ac",
",",
"conf",
".",
"Trust",
",",
"conf",
".",
"ConsistentCacheControlConfig",
",",
"conf",
".",
"CurrentCacheControlConfig",
",",
"conf",
".",
"RepoPrefixes",
")",
",",
"}",
"\n\n",
"logrus",
".",
"Info",
"(",
"\"",
"\"",
",",
"conf",
".",
"Addr",
")",
"\n\n",
"err",
"=",
"svr",
".",
"Serve",
"(",
"lsnr",
")",
"\n\n",
"return",
"err",
"\n",
"}"
] |
// Run sets up and starts a TLS server that can be cancelled using the
// given configuration. The context it is passed is the context it should
// use directly for the TLS server, and generate children off for requests
|
[
"Run",
"sets",
"up",
"and",
"starts",
"a",
"TLS",
"server",
"that",
"can",
"be",
"cancelled",
"using",
"the",
"given",
"configuration",
".",
"The",
"context",
"it",
"is",
"passed",
"is",
"the",
"context",
"it",
"should",
"use",
"directly",
"for",
"the",
"TLS",
"server",
"and",
"generate",
"children",
"off",
"for",
"requests"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/server.go#L51-L92
|
train
|
theupdateframework/notary
|
server/server.go
|
filterImagePrefixes
|
func filterImagePrefixes(requiredPrefixes []string, err error, handler http.Handler) http.Handler {
if len(requiredPrefixes) == 0 {
return handler
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gun := mux.Vars(r)["gun"]
if gun == "" {
handler.ServeHTTP(w, r)
return
}
for _, prefix := range requiredPrefixes {
if strings.HasPrefix(gun, prefix) {
handler.ServeHTTP(w, r)
return
}
}
errcode.ServeJSON(w, err)
})
}
|
go
|
func filterImagePrefixes(requiredPrefixes []string, err error, handler http.Handler) http.Handler {
if len(requiredPrefixes) == 0 {
return handler
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
gun := mux.Vars(r)["gun"]
if gun == "" {
handler.ServeHTTP(w, r)
return
}
for _, prefix := range requiredPrefixes {
if strings.HasPrefix(gun, prefix) {
handler.ServeHTTP(w, r)
return
}
}
errcode.ServeJSON(w, err)
})
}
|
[
"func",
"filterImagePrefixes",
"(",
"requiredPrefixes",
"[",
"]",
"string",
",",
"err",
"error",
",",
"handler",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"if",
"len",
"(",
"requiredPrefixes",
")",
"==",
"0",
"{",
"return",
"handler",
"\n",
"}",
"\n\n",
"return",
"http",
".",
"HandlerFunc",
"(",
"func",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"gun",
":=",
"mux",
".",
"Vars",
"(",
"r",
")",
"[",
"\"",
"\"",
"]",
"\n\n",
"if",
"gun",
"==",
"\"",
"\"",
"{",
"handler",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
")",
"\n",
"return",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"prefix",
":=",
"range",
"requiredPrefixes",
"{",
"if",
"strings",
".",
"HasPrefix",
"(",
"gun",
",",
"prefix",
")",
"{",
"handler",
".",
"ServeHTTP",
"(",
"w",
",",
"r",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"errcode",
".",
"ServeJSON",
"(",
"w",
",",
"err",
")",
"\n",
"}",
")",
"\n",
"}"
] |
// assumes that required prefixes is not empty
|
[
"assumes",
"that",
"required",
"prefixes",
"is",
"not",
"empty"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/server.go#L95-L117
|
train
|
theupdateframework/notary
|
server/server.go
|
CreateHandler
|
func CreateHandler(operationName string, serverHandler utils.ContextHandler, errorIfGUNInvalid error, includeCacheHeaders bool, cacheControlConfig utils.CacheControlConfig, permissionsRequired []string, authWrapper utils.AuthWrapper, repoPrefixes []string) http.Handler {
var wrapped http.Handler
wrapped = authWrapper(serverHandler, permissionsRequired...)
if includeCacheHeaders {
wrapped = utils.WrapWithCacheHandler(cacheControlConfig, wrapped)
}
wrapped = filterImagePrefixes(repoPrefixes, errorIfGUNInvalid, wrapped)
return prometheus.InstrumentHandlerWithOpts(prometheusOpts(operationName), wrapped)
}
|
go
|
func CreateHandler(operationName string, serverHandler utils.ContextHandler, errorIfGUNInvalid error, includeCacheHeaders bool, cacheControlConfig utils.CacheControlConfig, permissionsRequired []string, authWrapper utils.AuthWrapper, repoPrefixes []string) http.Handler {
var wrapped http.Handler
wrapped = authWrapper(serverHandler, permissionsRequired...)
if includeCacheHeaders {
wrapped = utils.WrapWithCacheHandler(cacheControlConfig, wrapped)
}
wrapped = filterImagePrefixes(repoPrefixes, errorIfGUNInvalid, wrapped)
return prometheus.InstrumentHandlerWithOpts(prometheusOpts(operationName), wrapped)
}
|
[
"func",
"CreateHandler",
"(",
"operationName",
"string",
",",
"serverHandler",
"utils",
".",
"ContextHandler",
",",
"errorIfGUNInvalid",
"error",
",",
"includeCacheHeaders",
"bool",
",",
"cacheControlConfig",
"utils",
".",
"CacheControlConfig",
",",
"permissionsRequired",
"[",
"]",
"string",
",",
"authWrapper",
"utils",
".",
"AuthWrapper",
",",
"repoPrefixes",
"[",
"]",
"string",
")",
"http",
".",
"Handler",
"{",
"var",
"wrapped",
"http",
".",
"Handler",
"\n",
"wrapped",
"=",
"authWrapper",
"(",
"serverHandler",
",",
"permissionsRequired",
"...",
")",
"\n",
"if",
"includeCacheHeaders",
"{",
"wrapped",
"=",
"utils",
".",
"WrapWithCacheHandler",
"(",
"cacheControlConfig",
",",
"wrapped",
")",
"\n",
"}",
"\n",
"wrapped",
"=",
"filterImagePrefixes",
"(",
"repoPrefixes",
",",
"errorIfGUNInvalid",
",",
"wrapped",
")",
"\n",
"return",
"prometheus",
".",
"InstrumentHandlerWithOpts",
"(",
"prometheusOpts",
"(",
"operationName",
")",
",",
"wrapped",
")",
"\n",
"}"
] |
// CreateHandler creates a server handler, wrapping with auth, caching, and monitoring
|
[
"CreateHandler",
"creates",
"a",
"server",
"handler",
"wrapping",
"with",
"auth",
"caching",
"and",
"monitoring"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/server.go#L120-L128
|
train
|
theupdateframework/notary
|
cmd/notary/keys.go
|
keyRemove
|
func (k *keyCommander) keyRemove(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmd.Usage()
return fmt.Errorf("must specify the key ID of the key to remove")
}
config, err := k.configGetter()
if err != nil {
return err
}
ks, err := k.getKeyStores(config, true, false)
if err != nil {
return err
}
keyID := args[0]
// This is an invalid ID
if len(keyID) != notary.SHA256HexSize {
return fmt.Errorf("invalid key ID provided: %s", keyID)
}
cmd.Println("")
err = removeKeyInteractively(ks, keyID, k.input, cmd.OutOrStdout())
cmd.Println("")
return err
}
|
go
|
func (k *keyCommander) keyRemove(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmd.Usage()
return fmt.Errorf("must specify the key ID of the key to remove")
}
config, err := k.configGetter()
if err != nil {
return err
}
ks, err := k.getKeyStores(config, true, false)
if err != nil {
return err
}
keyID := args[0]
// This is an invalid ID
if len(keyID) != notary.SHA256HexSize {
return fmt.Errorf("invalid key ID provided: %s", keyID)
}
cmd.Println("")
err = removeKeyInteractively(ks, keyID, k.input, cmd.OutOrStdout())
cmd.Println("")
return err
}
|
[
"func",
"(",
"k",
"*",
"keyCommander",
")",
"keyRemove",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"args",
")",
"<",
"1",
"{",
"cmd",
".",
"Usage",
"(",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"config",
",",
"err",
":=",
"k",
".",
"configGetter",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ks",
",",
"err",
":=",
"k",
".",
"getKeyStores",
"(",
"config",
",",
"true",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"keyID",
":=",
"args",
"[",
"0",
"]",
"\n\n",
"// This is an invalid ID",
"if",
"len",
"(",
"keyID",
")",
"!=",
"notary",
".",
"SHA256HexSize",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyID",
")",
"\n",
"}",
"\n",
"cmd",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"err",
"=",
"removeKeyInteractively",
"(",
"ks",
",",
"keyID",
",",
"k",
".",
"input",
",",
"cmd",
".",
"OutOrStdout",
"(",
")",
")",
"\n",
"cmd",
".",
"Println",
"(",
"\"",
"\"",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// keyRemove deletes a private key based on ID
|
[
"keyRemove",
"deletes",
"a",
"private",
"key",
"based",
"on",
"ID"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary/keys.go#L415-L439
|
train
|
theupdateframework/notary
|
cmd/notary/keys.go
|
keyPassphraseChange
|
func (k *keyCommander) keyPassphraseChange(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmd.Usage()
return fmt.Errorf("must specify the key ID of the key to change the passphrase of")
}
config, err := k.configGetter()
if err != nil {
return err
}
ks, err := k.getKeyStores(config, true, false)
if err != nil {
return err
}
keyID := args[0]
// This is an invalid ID
if len(keyID) != notary.SHA256HexSize {
return fmt.Errorf("invalid key ID provided: %s", keyID)
}
// Find which keyStore we should replace the key password in, and replace if we find it
var foundKeyStore trustmanager.KeyStore
var privKey data.PrivateKey
var keyInfo trustmanager.KeyInfo
var cs *cryptoservice.CryptoService
for _, keyStore := range ks {
cs = cryptoservice.NewCryptoService(keyStore)
if privKey, _, err = cs.GetPrivateKey(keyID); err == nil {
foundKeyStore = keyStore
break
}
}
if foundKeyStore == nil {
return fmt.Errorf("could not retrieve local key for key ID provided: %s", keyID)
}
// Must use a different passphrase retriever to avoid caching the
// unlocking passphrase and reusing that.
passChangeRetriever := k.getRetriever()
var addingKeyStore trustmanager.KeyStore
switch foundKeyStore.Name() {
case "yubikey":
addingKeyStore, err = getYubiStore(nil, passChangeRetriever)
keyInfo = trustmanager.KeyInfo{Role: data.CanonicalRootRole}
default:
addingKeyStore, err = trustmanager.NewKeyFileStore(config.GetString("trust_dir"), passChangeRetriever)
if err != nil {
return err
}
keyInfo, err = foundKeyStore.GetKeyInfo(keyID)
}
if err != nil {
return err
}
err = addingKeyStore.AddKey(keyInfo, privKey)
if err != nil {
return err
}
cmd.Printf("\nSuccessfully updated passphrase for key ID: %s\n", keyID)
return nil
}
|
go
|
func (k *keyCommander) keyPassphraseChange(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
cmd.Usage()
return fmt.Errorf("must specify the key ID of the key to change the passphrase of")
}
config, err := k.configGetter()
if err != nil {
return err
}
ks, err := k.getKeyStores(config, true, false)
if err != nil {
return err
}
keyID := args[0]
// This is an invalid ID
if len(keyID) != notary.SHA256HexSize {
return fmt.Errorf("invalid key ID provided: %s", keyID)
}
// Find which keyStore we should replace the key password in, and replace if we find it
var foundKeyStore trustmanager.KeyStore
var privKey data.PrivateKey
var keyInfo trustmanager.KeyInfo
var cs *cryptoservice.CryptoService
for _, keyStore := range ks {
cs = cryptoservice.NewCryptoService(keyStore)
if privKey, _, err = cs.GetPrivateKey(keyID); err == nil {
foundKeyStore = keyStore
break
}
}
if foundKeyStore == nil {
return fmt.Errorf("could not retrieve local key for key ID provided: %s", keyID)
}
// Must use a different passphrase retriever to avoid caching the
// unlocking passphrase and reusing that.
passChangeRetriever := k.getRetriever()
var addingKeyStore trustmanager.KeyStore
switch foundKeyStore.Name() {
case "yubikey":
addingKeyStore, err = getYubiStore(nil, passChangeRetriever)
keyInfo = trustmanager.KeyInfo{Role: data.CanonicalRootRole}
default:
addingKeyStore, err = trustmanager.NewKeyFileStore(config.GetString("trust_dir"), passChangeRetriever)
if err != nil {
return err
}
keyInfo, err = foundKeyStore.GetKeyInfo(keyID)
}
if err != nil {
return err
}
err = addingKeyStore.AddKey(keyInfo, privKey)
if err != nil {
return err
}
cmd.Printf("\nSuccessfully updated passphrase for key ID: %s\n", keyID)
return nil
}
|
[
"func",
"(",
"k",
"*",
"keyCommander",
")",
"keyPassphraseChange",
"(",
"cmd",
"*",
"cobra",
".",
"Command",
",",
"args",
"[",
"]",
"string",
")",
"error",
"{",
"if",
"len",
"(",
"args",
")",
"<",
"1",
"{",
"cmd",
".",
"Usage",
"(",
")",
"\n",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"config",
",",
"err",
":=",
"k",
".",
"configGetter",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"ks",
",",
"err",
":=",
"k",
".",
"getKeyStores",
"(",
"config",
",",
"true",
",",
"false",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"keyID",
":=",
"args",
"[",
"0",
"]",
"\n\n",
"// This is an invalid ID",
"if",
"len",
"(",
"keyID",
")",
"!=",
"notary",
".",
"SHA256HexSize",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyID",
")",
"\n",
"}",
"\n\n",
"// Find which keyStore we should replace the key password in, and replace if we find it",
"var",
"foundKeyStore",
"trustmanager",
".",
"KeyStore",
"\n",
"var",
"privKey",
"data",
".",
"PrivateKey",
"\n",
"var",
"keyInfo",
"trustmanager",
".",
"KeyInfo",
"\n",
"var",
"cs",
"*",
"cryptoservice",
".",
"CryptoService",
"\n",
"for",
"_",
",",
"keyStore",
":=",
"range",
"ks",
"{",
"cs",
"=",
"cryptoservice",
".",
"NewCryptoService",
"(",
"keyStore",
")",
"\n",
"if",
"privKey",
",",
"_",
",",
"err",
"=",
"cs",
".",
"GetPrivateKey",
"(",
"keyID",
")",
";",
"err",
"==",
"nil",
"{",
"foundKeyStore",
"=",
"keyStore",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"foundKeyStore",
"==",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyID",
")",
"\n",
"}",
"\n",
"// Must use a different passphrase retriever to avoid caching the",
"// unlocking passphrase and reusing that.",
"passChangeRetriever",
":=",
"k",
".",
"getRetriever",
"(",
")",
"\n",
"var",
"addingKeyStore",
"trustmanager",
".",
"KeyStore",
"\n",
"switch",
"foundKeyStore",
".",
"Name",
"(",
")",
"{",
"case",
"\"",
"\"",
":",
"addingKeyStore",
",",
"err",
"=",
"getYubiStore",
"(",
"nil",
",",
"passChangeRetriever",
")",
"\n",
"keyInfo",
"=",
"trustmanager",
".",
"KeyInfo",
"{",
"Role",
":",
"data",
".",
"CanonicalRootRole",
"}",
"\n",
"default",
":",
"addingKeyStore",
",",
"err",
"=",
"trustmanager",
".",
"NewKeyFileStore",
"(",
"config",
".",
"GetString",
"(",
"\"",
"\"",
")",
",",
"passChangeRetriever",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"keyInfo",
",",
"err",
"=",
"foundKeyStore",
".",
"GetKeyInfo",
"(",
"keyID",
")",
"\n",
"}",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"err",
"=",
"addingKeyStore",
".",
"AddKey",
"(",
"keyInfo",
",",
"privKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"cmd",
".",
"Printf",
"(",
"\"",
"\\n",
"\\n",
"\"",
",",
"keyID",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// keyPassphraseChange changes the passphrase for a private key based on ID
|
[
"keyPassphraseChange",
"changes",
"the",
"passphrase",
"for",
"a",
"private",
"key",
"based",
"on",
"ID"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary/keys.go#L442-L503
|
train
|
theupdateframework/notary
|
cmd/notary-signer/main.go
|
debugServer
|
func debugServer(addr string) {
logrus.Infof("Debug server listening on %s", addr)
if err := http.ListenAndServe(addr, nil); err != nil {
logrus.Fatalf("error listening on debug interface: %v", err)
}
}
|
go
|
func debugServer(addr string) {
logrus.Infof("Debug server listening on %s", addr)
if err := http.ListenAndServe(addr, nil); err != nil {
logrus.Fatalf("error listening on debug interface: %v", err)
}
}
|
[
"func",
"debugServer",
"(",
"addr",
"string",
")",
"{",
"logrus",
".",
"Infof",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"if",
"err",
":=",
"http",
".",
"ListenAndServe",
"(",
"addr",
",",
"nil",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Fatalf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// debugServer starts the debug server with pprof, expvar among other
// endpoints. The addr should not be exposed externally. For most of these to
// work, tls cannot be enabled on the endpoint, so it is generally separate.
|
[
"debugServer",
"starts",
"the",
"debug",
"server",
"with",
"pprof",
"expvar",
"among",
"other",
"endpoints",
".",
"The",
"addr",
"should",
"not",
"be",
"exposed",
"externally",
".",
"For",
"most",
"of",
"these",
"to",
"work",
"tls",
"cannot",
"be",
"enabled",
"on",
"the",
"endpoint",
"so",
"it",
"is",
"generally",
"separate",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary-signer/main.go#L93-L98
|
train
|
theupdateframework/notary
|
utils/http.go
|
RootHandlerFactory
|
func RootHandlerFactory(ctx context.Context, auth auth.AccessController, trust signed.CryptoService) func(ContextHandler, ...string) *rootHandler {
return func(handler ContextHandler, actions ...string) *rootHandler {
return &rootHandler{
handler: handler,
auth: auth,
actions: actions,
context: ctx,
trust: trust,
}
}
}
|
go
|
func RootHandlerFactory(ctx context.Context, auth auth.AccessController, trust signed.CryptoService) func(ContextHandler, ...string) *rootHandler {
return func(handler ContextHandler, actions ...string) *rootHandler {
return &rootHandler{
handler: handler,
auth: auth,
actions: actions,
context: ctx,
trust: trust,
}
}
}
|
[
"func",
"RootHandlerFactory",
"(",
"ctx",
"context",
".",
"Context",
",",
"auth",
"auth",
".",
"AccessController",
",",
"trust",
"signed",
".",
"CryptoService",
")",
"func",
"(",
"ContextHandler",
",",
"...",
"string",
")",
"*",
"rootHandler",
"{",
"return",
"func",
"(",
"handler",
"ContextHandler",
",",
"actions",
"...",
"string",
")",
"*",
"rootHandler",
"{",
"return",
"&",
"rootHandler",
"{",
"handler",
":",
"handler",
",",
"auth",
":",
"auth",
",",
"actions",
":",
"actions",
",",
"context",
":",
"ctx",
",",
"trust",
":",
"trust",
",",
"}",
"\n",
"}",
"\n",
"}"
] |
// RootHandlerFactory creates a new rootHandler factory using the given
// Context creator and authorizer. The returned factory allows creating
// new rootHandlers from the alternate http handler contextHandler and
// a scope.
|
[
"RootHandlerFactory",
"creates",
"a",
"new",
"rootHandler",
"factory",
"using",
"the",
"given",
"Context",
"creator",
"and",
"authorizer",
".",
"The",
"returned",
"factory",
"allows",
"creating",
"new",
"rootHandlers",
"from",
"the",
"alternate",
"http",
"handler",
"contextHandler",
"and",
"a",
"scope",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/http.go#L39-L49
|
train
|
theupdateframework/notary
|
utils/http.go
|
ServeHTTP
|
func (root *rootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var (
err error
ctx = ctxu.WithRequest(root.context, r)
log = ctxu.GetRequestLogger(ctx)
vars = mux.Vars(r)
)
ctx, w = ctxu.WithResponseWriter(ctx, w)
ctx = ctxu.WithLogger(ctx, log)
ctx = context.WithValue(ctx, notary.CtxKeyCryptoSvc, root.trust)
defer func(ctx context.Context) {
ctxu.GetResponseLogger(ctx).Info("response completed")
}(ctx)
if root.auth != nil {
ctx = context.WithValue(ctx, notary.CtxKeyRepo, vars["gun"])
if ctx, err = root.doAuth(ctx, vars["gun"], w); err != nil {
// errors have already been logged/output to w inside doAuth
// just return
return
}
}
if err := root.handler(ctx, w, r); err != nil {
serveError(log, w, err)
}
}
|
go
|
func (root *rootHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var (
err error
ctx = ctxu.WithRequest(root.context, r)
log = ctxu.GetRequestLogger(ctx)
vars = mux.Vars(r)
)
ctx, w = ctxu.WithResponseWriter(ctx, w)
ctx = ctxu.WithLogger(ctx, log)
ctx = context.WithValue(ctx, notary.CtxKeyCryptoSvc, root.trust)
defer func(ctx context.Context) {
ctxu.GetResponseLogger(ctx).Info("response completed")
}(ctx)
if root.auth != nil {
ctx = context.WithValue(ctx, notary.CtxKeyRepo, vars["gun"])
if ctx, err = root.doAuth(ctx, vars["gun"], w); err != nil {
// errors have already been logged/output to w inside doAuth
// just return
return
}
}
if err := root.handler(ctx, w, r); err != nil {
serveError(log, w, err)
}
}
|
[
"func",
"(",
"root",
"*",
"rootHandler",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"var",
"(",
"err",
"error",
"\n",
"ctx",
"=",
"ctxu",
".",
"WithRequest",
"(",
"root",
".",
"context",
",",
"r",
")",
"\n",
"log",
"=",
"ctxu",
".",
"GetRequestLogger",
"(",
"ctx",
")",
"\n",
"vars",
"=",
"mux",
".",
"Vars",
"(",
"r",
")",
"\n",
")",
"\n",
"ctx",
",",
"w",
"=",
"ctxu",
".",
"WithResponseWriter",
"(",
"ctx",
",",
"w",
")",
"\n",
"ctx",
"=",
"ctxu",
".",
"WithLogger",
"(",
"ctx",
",",
"log",
")",
"\n",
"ctx",
"=",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"notary",
".",
"CtxKeyCryptoSvc",
",",
"root",
".",
"trust",
")",
"\n\n",
"defer",
"func",
"(",
"ctx",
"context",
".",
"Context",
")",
"{",
"ctxu",
".",
"GetResponseLogger",
"(",
"ctx",
")",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"}",
"(",
"ctx",
")",
"\n\n",
"if",
"root",
".",
"auth",
"!=",
"nil",
"{",
"ctx",
"=",
"context",
".",
"WithValue",
"(",
"ctx",
",",
"notary",
".",
"CtxKeyRepo",
",",
"vars",
"[",
"\"",
"\"",
"]",
")",
"\n",
"if",
"ctx",
",",
"err",
"=",
"root",
".",
"doAuth",
"(",
"ctx",
",",
"vars",
"[",
"\"",
"\"",
"]",
",",
"w",
")",
";",
"err",
"!=",
"nil",
"{",
"// errors have already been logged/output to w inside doAuth",
"// just return",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"root",
".",
"handler",
"(",
"ctx",
",",
"w",
",",
"r",
")",
";",
"err",
"!=",
"nil",
"{",
"serveError",
"(",
"log",
",",
"w",
",",
"err",
")",
"\n",
"}",
"\n",
"}"
] |
// ServeHTTP serves an HTTP request and implements the http.Handler interface.
|
[
"ServeHTTP",
"serves",
"an",
"HTTP",
"request",
"and",
"implements",
"the",
"http",
".",
"Handler",
"interface",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/http.go#L52-L78
|
train
|
theupdateframework/notary
|
utils/http.go
|
buildCatalogRecord
|
func buildCatalogRecord(actions ...string) []auth.Access {
requiredAccess := []auth.Access{{
Resource: auth.Resource{
Type: "registry",
Name: "catalog",
},
Action: "*",
}}
return requiredAccess
}
|
go
|
func buildCatalogRecord(actions ...string) []auth.Access {
requiredAccess := []auth.Access{{
Resource: auth.Resource{
Type: "registry",
Name: "catalog",
},
Action: "*",
}}
return requiredAccess
}
|
[
"func",
"buildCatalogRecord",
"(",
"actions",
"...",
"string",
")",
"[",
"]",
"auth",
".",
"Access",
"{",
"requiredAccess",
":=",
"[",
"]",
"auth",
".",
"Access",
"{",
"{",
"Resource",
":",
"auth",
".",
"Resource",
"{",
"Type",
":",
"\"",
"\"",
",",
"Name",
":",
"\"",
"\"",
",",
"}",
",",
"Action",
":",
"\"",
"\"",
",",
"}",
"}",
"\n\n",
"return",
"requiredAccess",
"\n",
"}"
] |
// buildCatalogRecord returns the only valid format for the catalog
// resource. Only admins can get this access level from the token
// server.
|
[
"buildCatalogRecord",
"returns",
"the",
"only",
"valid",
"format",
"for",
"the",
"catalog",
"resource",
".",
"Only",
"admins",
"can",
"get",
"this",
"access",
"level",
"from",
"the",
"token",
"server",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/http.go#L143-L153
|
train
|
theupdateframework/notary
|
utils/http.go
|
NewCacheControlConfig
|
func NewCacheControlConfig(maxAgeInSeconds int, mustRevalidate bool) CacheControlConfig {
if maxAgeInSeconds > 0 {
return PublicCacheControl{MustReValidate: mustRevalidate, MaxAgeInSeconds: maxAgeInSeconds}
}
return NoCacheControl{}
}
|
go
|
func NewCacheControlConfig(maxAgeInSeconds int, mustRevalidate bool) CacheControlConfig {
if maxAgeInSeconds > 0 {
return PublicCacheControl{MustReValidate: mustRevalidate, MaxAgeInSeconds: maxAgeInSeconds}
}
return NoCacheControl{}
}
|
[
"func",
"NewCacheControlConfig",
"(",
"maxAgeInSeconds",
"int",
",",
"mustRevalidate",
"bool",
")",
"CacheControlConfig",
"{",
"if",
"maxAgeInSeconds",
">",
"0",
"{",
"return",
"PublicCacheControl",
"{",
"MustReValidate",
":",
"mustRevalidate",
",",
"MaxAgeInSeconds",
":",
"maxAgeInSeconds",
"}",
"\n",
"}",
"\n",
"return",
"NoCacheControl",
"{",
"}",
"\n",
"}"
] |
// NewCacheControlConfig returns CacheControlConfig interface for either setting
// cache control or disabling cache control entirely
|
[
"NewCacheControlConfig",
"returns",
"CacheControlConfig",
"interface",
"for",
"either",
"setting",
"cache",
"control",
"or",
"disabling",
"cache",
"control",
"entirely"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/http.go#L164-L169
|
train
|
theupdateframework/notary
|
utils/http.go
|
SetHeaders
|
func (p PublicCacheControl) SetHeaders(headers http.Header) {
cacheControlValue := fmt.Sprintf("public, max-age=%v, s-maxage=%v",
p.MaxAgeInSeconds, p.MaxAgeInSeconds)
if p.MustReValidate {
cacheControlValue = fmt.Sprintf("%s, must-revalidate", cacheControlValue)
}
headers.Set("Cache-Control", cacheControlValue)
// delete the Pragma directive, because the only valid value in HTTP is
// "no-cache"
headers.Del("Pragma")
if headers.Get("Last-Modified") == "" {
SetLastModifiedHeader(headers, time.Time{})
}
}
|
go
|
func (p PublicCacheControl) SetHeaders(headers http.Header) {
cacheControlValue := fmt.Sprintf("public, max-age=%v, s-maxage=%v",
p.MaxAgeInSeconds, p.MaxAgeInSeconds)
if p.MustReValidate {
cacheControlValue = fmt.Sprintf("%s, must-revalidate", cacheControlValue)
}
headers.Set("Cache-Control", cacheControlValue)
// delete the Pragma directive, because the only valid value in HTTP is
// "no-cache"
headers.Del("Pragma")
if headers.Get("Last-Modified") == "" {
SetLastModifiedHeader(headers, time.Time{})
}
}
|
[
"func",
"(",
"p",
"PublicCacheControl",
")",
"SetHeaders",
"(",
"headers",
"http",
".",
"Header",
")",
"{",
"cacheControlValue",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"p",
".",
"MaxAgeInSeconds",
",",
"p",
".",
"MaxAgeInSeconds",
")",
"\n\n",
"if",
"p",
".",
"MustReValidate",
"{",
"cacheControlValue",
"=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"cacheControlValue",
")",
"\n",
"}",
"\n",
"headers",
".",
"Set",
"(",
"\"",
"\"",
",",
"cacheControlValue",
")",
"\n",
"// delete the Pragma directive, because the only valid value in HTTP is",
"// \"no-cache\"",
"headers",
".",
"Del",
"(",
"\"",
"\"",
")",
"\n",
"if",
"headers",
".",
"Get",
"(",
"\"",
"\"",
")",
"==",
"\"",
"\"",
"{",
"SetLastModifiedHeader",
"(",
"headers",
",",
"time",
".",
"Time",
"{",
"}",
")",
"\n",
"}",
"\n",
"}"
] |
// SetHeaders sets the public headers with an optional must-revalidate header
|
[
"SetHeaders",
"sets",
"the",
"public",
"headers",
"with",
"an",
"optional",
"must",
"-",
"revalidate",
"header"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/http.go#L178-L192
|
train
|
theupdateframework/notary
|
utils/http.go
|
SetHeaders
|
func (n NoCacheControl) SetHeaders(headers http.Header) {
headers.Set("Cache-Control", "max-age=0, no-cache, no-store")
headers.Set("Pragma", "no-cache")
}
|
go
|
func (n NoCacheControl) SetHeaders(headers http.Header) {
headers.Set("Cache-Control", "max-age=0, no-cache, no-store")
headers.Set("Pragma", "no-cache")
}
|
[
"func",
"(",
"n",
"NoCacheControl",
")",
"SetHeaders",
"(",
"headers",
"http",
".",
"Header",
")",
"{",
"headers",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"headers",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"}"
] |
// SetHeaders sets the public headers cache-control headers and pragma to no-cache
|
[
"SetHeaders",
"sets",
"the",
"public",
"headers",
"cache",
"-",
"control",
"headers",
"and",
"pragma",
"to",
"no",
"-",
"cache"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/http.go#L198-L201
|
train
|
theupdateframework/notary
|
utils/http.go
|
WriteHeader
|
func (c *cacheControlResponseWriter) WriteHeader(statusCode int) {
c.statusCode = statusCode
c.ResponseWriter.WriteHeader(statusCode)
}
|
go
|
func (c *cacheControlResponseWriter) WriteHeader(statusCode int) {
c.statusCode = statusCode
c.ResponseWriter.WriteHeader(statusCode)
}
|
[
"func",
"(",
"c",
"*",
"cacheControlResponseWriter",
")",
"WriteHeader",
"(",
"statusCode",
"int",
")",
"{",
"c",
".",
"statusCode",
"=",
"statusCode",
"\n",
"c",
".",
"ResponseWriter",
".",
"WriteHeader",
"(",
"statusCode",
")",
"\n",
"}"
] |
// WriteHeader stores the header before writing it, so we can tell if it's been set
// to a non-200 status code
|
[
"WriteHeader",
"stores",
"the",
"header",
"before",
"writing",
"it",
"so",
"we",
"can",
"tell",
"if",
"it",
"s",
"been",
"set",
"to",
"a",
"non",
"-",
"200",
"status",
"code"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/http.go#L213-L216
|
train
|
theupdateframework/notary
|
utils/http.go
|
Write
|
func (c *cacheControlResponseWriter) Write(data []byte) (int, error) {
if c.statusCode == http.StatusOK || c.statusCode == 0 {
headers := c.ResponseWriter.Header()
if headers.Get("Cache-Control") == "" {
c.config.SetHeaders(headers)
}
}
return c.ResponseWriter.Write(data)
}
|
go
|
func (c *cacheControlResponseWriter) Write(data []byte) (int, error) {
if c.statusCode == http.StatusOK || c.statusCode == 0 {
headers := c.ResponseWriter.Header()
if headers.Get("Cache-Control") == "" {
c.config.SetHeaders(headers)
}
}
return c.ResponseWriter.Write(data)
}
|
[
"func",
"(",
"c",
"*",
"cacheControlResponseWriter",
")",
"Write",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"int",
",",
"error",
")",
"{",
"if",
"c",
".",
"statusCode",
"==",
"http",
".",
"StatusOK",
"||",
"c",
".",
"statusCode",
"==",
"0",
"{",
"headers",
":=",
"c",
".",
"ResponseWriter",
".",
"Header",
"(",
")",
"\n",
"if",
"headers",
".",
"Get",
"(",
"\"",
"\"",
")",
"==",
"\"",
"\"",
"{",
"c",
".",
"config",
".",
"SetHeaders",
"(",
"headers",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"c",
".",
"ResponseWriter",
".",
"Write",
"(",
"data",
")",
"\n",
"}"
] |
// Write will set the cache headers if they haven't already been set and if the status
// code has either not been set or set to 200
|
[
"Write",
"will",
"set",
"the",
"cache",
"headers",
"if",
"they",
"haven",
"t",
"already",
"been",
"set",
"and",
"if",
"the",
"status",
"code",
"has",
"either",
"not",
"been",
"set",
"or",
"set",
"to",
"200"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/http.go#L220-L228
|
train
|
theupdateframework/notary
|
utils/http.go
|
WrapWithCacheHandler
|
func WrapWithCacheHandler(ccc CacheControlConfig, handler http.Handler) http.Handler {
if ccc != nil {
return cacheControlHandler{Handler: handler, config: ccc}
}
return handler
}
|
go
|
func WrapWithCacheHandler(ccc CacheControlConfig, handler http.Handler) http.Handler {
if ccc != nil {
return cacheControlHandler{Handler: handler, config: ccc}
}
return handler
}
|
[
"func",
"WrapWithCacheHandler",
"(",
"ccc",
"CacheControlConfig",
",",
"handler",
"http",
".",
"Handler",
")",
"http",
".",
"Handler",
"{",
"if",
"ccc",
"!=",
"nil",
"{",
"return",
"cacheControlHandler",
"{",
"Handler",
":",
"handler",
",",
"config",
":",
"ccc",
"}",
"\n",
"}",
"\n",
"return",
"handler",
"\n",
"}"
] |
// WrapWithCacheHandler wraps another handler in one that can add cache control headers
// given a 200 response
|
[
"WrapWithCacheHandler",
"wraps",
"another",
"handler",
"in",
"one",
"that",
"can",
"add",
"cache",
"control",
"headers",
"given",
"a",
"200",
"response"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/http.go#L241-L246
|
train
|
theupdateframework/notary
|
utils/http.go
|
SetLastModifiedHeader
|
func SetLastModifiedHeader(headers http.Header, lmt time.Time) {
headers.Set("Last-Modified", lmt.Format(time.RFC1123))
}
|
go
|
func SetLastModifiedHeader(headers http.Header, lmt time.Time) {
headers.Set("Last-Modified", lmt.Format(time.RFC1123))
}
|
[
"func",
"SetLastModifiedHeader",
"(",
"headers",
"http",
".",
"Header",
",",
"lmt",
"time",
".",
"Time",
")",
"{",
"headers",
".",
"Set",
"(",
"\"",
"\"",
",",
"lmt",
".",
"Format",
"(",
"time",
".",
"RFC1123",
")",
")",
"\n",
"}"
] |
// SetLastModifiedHeader takes a time and uses it to set the LastModified header using
// the right date format
|
[
"SetLastModifiedHeader",
"takes",
"a",
"time",
"and",
"uses",
"it",
"to",
"set",
"the",
"LastModified",
"header",
"using",
"the",
"right",
"date",
"format"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/utils/http.go#L250-L252
|
train
|
theupdateframework/notary
|
client/tufclient.go
|
Update
|
func (c *tufClient) Update() (*tuf.Repo, *tuf.Repo, error) {
// 1. Get timestamp
// a. If timestamp error (verification, expired, etc...) download new root and return to 1.
// 2. Check if local snapshot is up to date
// a. If out of date, get updated snapshot
// i. If snapshot error, download new root and return to 1.
// 3. Check if root correct against snapshot
// a. If incorrect, download new root and return to 1.
// 4. Iteratively download and search targets and delegations to find target meta
logrus.Debug("updating TUF client")
err := c.update()
if err != nil {
logrus.Debug("Error occurred. Root will be downloaded and another update attempted")
logrus.Debug("Resetting the TUF builder...")
c.newBuilder = c.newBuilder.BootstrapNewBuilder()
if err := c.updateRoot(); err != nil {
logrus.Debug("Client Update (Root): ", err)
return nil, nil, err
}
// If we error again, we now have the latest root and just want to fail
// out as there's no expectation the problem can be resolved automatically
logrus.Debug("retrying TUF client update")
if err := c.update(); err != nil {
return nil, nil, err
}
}
return c.newBuilder.Finish()
}
|
go
|
func (c *tufClient) Update() (*tuf.Repo, *tuf.Repo, error) {
// 1. Get timestamp
// a. If timestamp error (verification, expired, etc...) download new root and return to 1.
// 2. Check if local snapshot is up to date
// a. If out of date, get updated snapshot
// i. If snapshot error, download new root and return to 1.
// 3. Check if root correct against snapshot
// a. If incorrect, download new root and return to 1.
// 4. Iteratively download and search targets and delegations to find target meta
logrus.Debug("updating TUF client")
err := c.update()
if err != nil {
logrus.Debug("Error occurred. Root will be downloaded and another update attempted")
logrus.Debug("Resetting the TUF builder...")
c.newBuilder = c.newBuilder.BootstrapNewBuilder()
if err := c.updateRoot(); err != nil {
logrus.Debug("Client Update (Root): ", err)
return nil, nil, err
}
// If we error again, we now have the latest root and just want to fail
// out as there's no expectation the problem can be resolved automatically
logrus.Debug("retrying TUF client update")
if err := c.update(); err != nil {
return nil, nil, err
}
}
return c.newBuilder.Finish()
}
|
[
"func",
"(",
"c",
"*",
"tufClient",
")",
"Update",
"(",
")",
"(",
"*",
"tuf",
".",
"Repo",
",",
"*",
"tuf",
".",
"Repo",
",",
"error",
")",
"{",
"// 1. Get timestamp",
"// a. If timestamp error (verification, expired, etc...) download new root and return to 1.",
"// 2. Check if local snapshot is up to date",
"// a. If out of date, get updated snapshot",
"// i. If snapshot error, download new root and return to 1.",
"// 3. Check if root correct against snapshot",
"// a. If incorrect, download new root and return to 1.",
"// 4. Iteratively download and search targets and delegations to find target meta",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"err",
":=",
"c",
".",
"update",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n\n",
"c",
".",
"newBuilder",
"=",
"c",
".",
"newBuilder",
".",
"BootstrapNewBuilder",
"(",
")",
"\n\n",
"if",
"err",
":=",
"c",
".",
"updateRoot",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// If we error again, we now have the latest root and just want to fail",
"// out as there's no expectation the problem can be resolved automatically",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"if",
"err",
":=",
"c",
".",
"update",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"c",
".",
"newBuilder",
".",
"Finish",
"(",
")",
"\n",
"}"
] |
// Update performs an update to the TUF repo as defined by the TUF spec
|
[
"Update",
"performs",
"an",
"update",
"to",
"the",
"TUF",
"repo",
"as",
"defined",
"by",
"the",
"TUF",
"spec"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/tufclient.go#L27-L56
|
train
|
theupdateframework/notary
|
client/tufclient.go
|
updateRoot
|
func (c *tufClient) updateRoot() error {
// Get current root version
currentRootConsistentInfo := c.oldBuilder.GetConsistentInfo(data.CanonicalRootRole)
currentVersion := c.oldBuilder.GetLoadedVersion(currentRootConsistentInfo.RoleName)
// Get new root version
raw, err := c.downloadRoot()
switch err.(type) {
case *trustpinning.ErrRootRotationFail:
// Rotation errors are okay since we haven't yet downloaded
// all intermediate root files
break
case nil:
// No error updating root - we were at most 1 version behind
return nil
default:
// Return any non-rotation error.
return err
}
// Load current version into newBuilder
currentRaw, err := c.cache.GetSized(data.CanonicalRootRole.String(), -1)
if err != nil {
logrus.Debugf("error loading %d.%s: %s", currentVersion, data.CanonicalRootRole, err)
return err
}
if err := c.newBuilder.LoadRootForUpdate(currentRaw, currentVersion, false); err != nil {
logrus.Debugf("%d.%s is invalid: %s", currentVersion, data.CanonicalRootRole, err)
return err
}
// Extract newest version number
signedRoot := &data.Signed{}
if err := json.Unmarshal(raw, signedRoot); err != nil {
return err
}
newestRoot, err := data.RootFromSigned(signedRoot)
if err != nil {
return err
}
newestVersion := newestRoot.Signed.SignedCommon.Version
// Update from current + 1 (current already loaded) to newest - 1 (newest loaded below)
if err := c.updateRootVersions(currentVersion+1, newestVersion-1); err != nil {
return err
}
// Already downloaded newest, verify it against newest - 1
if err := c.newBuilder.LoadRootForUpdate(raw, newestVersion, true); err != nil {
logrus.Debugf("downloaded %d.%s is invalid: %s", newestVersion, data.CanonicalRootRole, err)
return err
}
logrus.Debugf("successfully verified downloaded %d.%s", newestVersion, data.CanonicalRootRole)
// Write newest to cache
if err := c.cache.Set(data.CanonicalRootRole.String(), raw); err != nil {
logrus.Debugf("unable to write %d.%s to cache: %s", newestVersion, data.CanonicalRootRole, err)
}
logrus.Debugf("finished updating root files")
return nil
}
|
go
|
func (c *tufClient) updateRoot() error {
// Get current root version
currentRootConsistentInfo := c.oldBuilder.GetConsistentInfo(data.CanonicalRootRole)
currentVersion := c.oldBuilder.GetLoadedVersion(currentRootConsistentInfo.RoleName)
// Get new root version
raw, err := c.downloadRoot()
switch err.(type) {
case *trustpinning.ErrRootRotationFail:
// Rotation errors are okay since we haven't yet downloaded
// all intermediate root files
break
case nil:
// No error updating root - we were at most 1 version behind
return nil
default:
// Return any non-rotation error.
return err
}
// Load current version into newBuilder
currentRaw, err := c.cache.GetSized(data.CanonicalRootRole.String(), -1)
if err != nil {
logrus.Debugf("error loading %d.%s: %s", currentVersion, data.CanonicalRootRole, err)
return err
}
if err := c.newBuilder.LoadRootForUpdate(currentRaw, currentVersion, false); err != nil {
logrus.Debugf("%d.%s is invalid: %s", currentVersion, data.CanonicalRootRole, err)
return err
}
// Extract newest version number
signedRoot := &data.Signed{}
if err := json.Unmarshal(raw, signedRoot); err != nil {
return err
}
newestRoot, err := data.RootFromSigned(signedRoot)
if err != nil {
return err
}
newestVersion := newestRoot.Signed.SignedCommon.Version
// Update from current + 1 (current already loaded) to newest - 1 (newest loaded below)
if err := c.updateRootVersions(currentVersion+1, newestVersion-1); err != nil {
return err
}
// Already downloaded newest, verify it against newest - 1
if err := c.newBuilder.LoadRootForUpdate(raw, newestVersion, true); err != nil {
logrus.Debugf("downloaded %d.%s is invalid: %s", newestVersion, data.CanonicalRootRole, err)
return err
}
logrus.Debugf("successfully verified downloaded %d.%s", newestVersion, data.CanonicalRootRole)
// Write newest to cache
if err := c.cache.Set(data.CanonicalRootRole.String(), raw); err != nil {
logrus.Debugf("unable to write %d.%s to cache: %s", newestVersion, data.CanonicalRootRole, err)
}
logrus.Debugf("finished updating root files")
return nil
}
|
[
"func",
"(",
"c",
"*",
"tufClient",
")",
"updateRoot",
"(",
")",
"error",
"{",
"// Get current root version",
"currentRootConsistentInfo",
":=",
"c",
".",
"oldBuilder",
".",
"GetConsistentInfo",
"(",
"data",
".",
"CanonicalRootRole",
")",
"\n",
"currentVersion",
":=",
"c",
".",
"oldBuilder",
".",
"GetLoadedVersion",
"(",
"currentRootConsistentInfo",
".",
"RoleName",
")",
"\n\n",
"// Get new root version",
"raw",
",",
"err",
":=",
"c",
".",
"downloadRoot",
"(",
")",
"\n\n",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"trustpinning",
".",
"ErrRootRotationFail",
":",
"// Rotation errors are okay since we haven't yet downloaded",
"// all intermediate root files",
"break",
"\n",
"case",
"nil",
":",
"// No error updating root - we were at most 1 version behind",
"return",
"nil",
"\n",
"default",
":",
"// Return any non-rotation error.",
"return",
"err",
"\n",
"}",
"\n\n",
"// Load current version into newBuilder",
"currentRaw",
",",
"err",
":=",
"c",
".",
"cache",
".",
"GetSized",
"(",
"data",
".",
"CanonicalRootRole",
".",
"String",
"(",
")",
",",
"-",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"currentVersion",
",",
"data",
".",
"CanonicalRootRole",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"newBuilder",
".",
"LoadRootForUpdate",
"(",
"currentRaw",
",",
"currentVersion",
",",
"false",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"currentVersion",
",",
"data",
".",
"CanonicalRootRole",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"// Extract newest version number",
"signedRoot",
":=",
"&",
"data",
".",
"Signed",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"raw",
",",
"signedRoot",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"newestRoot",
",",
"err",
":=",
"data",
".",
"RootFromSigned",
"(",
"signedRoot",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"newestVersion",
":=",
"newestRoot",
".",
"Signed",
".",
"SignedCommon",
".",
"Version",
"\n\n",
"// Update from current + 1 (current already loaded) to newest - 1 (newest loaded below)",
"if",
"err",
":=",
"c",
".",
"updateRootVersions",
"(",
"currentVersion",
"+",
"1",
",",
"newestVersion",
"-",
"1",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Already downloaded newest, verify it against newest - 1",
"if",
"err",
":=",
"c",
".",
"newBuilder",
".",
"LoadRootForUpdate",
"(",
"raw",
",",
"newestVersion",
",",
"true",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"newestVersion",
",",
"data",
".",
"CanonicalRootRole",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"newestVersion",
",",
"data",
".",
"CanonicalRootRole",
")",
"\n\n",
"// Write newest to cache",
"if",
"err",
":=",
"c",
".",
"cache",
".",
"Set",
"(",
"data",
".",
"CanonicalRootRole",
".",
"String",
"(",
")",
",",
"raw",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"newestVersion",
",",
"data",
".",
"CanonicalRootRole",
",",
"err",
")",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
"\n",
"}"
] |
// updateRoot checks if there is a newer version of the root available, and if so
// downloads all intermediate root files to allow proper key rotation.
|
[
"updateRoot",
"checks",
"if",
"there",
"is",
"a",
"newer",
"version",
"of",
"the",
"root",
"available",
"and",
"if",
"so",
"downloads",
"all",
"intermediate",
"root",
"files",
"to",
"allow",
"proper",
"key",
"rotation",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/tufclient.go#L77-L138
|
train
|
theupdateframework/notary
|
client/tufclient.go
|
updateRootVersions
|
func (c *tufClient) updateRootVersions(fromVersion, toVersion int) error {
for v := fromVersion; v <= toVersion; v++ {
logrus.Debugf("updating root from version %d to version %d, currently fetching %d", fromVersion, toVersion, v)
versionedRole := fmt.Sprintf("%d.%s", v, data.CanonicalRootRole)
raw, err := c.remote.GetSized(versionedRole, -1)
if err != nil {
logrus.Debugf("error downloading %s: %s", versionedRole, err)
return err
}
if err := c.newBuilder.LoadRootForUpdate(raw, v, false); err != nil {
logrus.Debugf("downloaded %s is invalid: %s", versionedRole, err)
return err
}
logrus.Debugf("successfully verified downloaded %s", versionedRole)
}
return nil
}
|
go
|
func (c *tufClient) updateRootVersions(fromVersion, toVersion int) error {
for v := fromVersion; v <= toVersion; v++ {
logrus.Debugf("updating root from version %d to version %d, currently fetching %d", fromVersion, toVersion, v)
versionedRole := fmt.Sprintf("%d.%s", v, data.CanonicalRootRole)
raw, err := c.remote.GetSized(versionedRole, -1)
if err != nil {
logrus.Debugf("error downloading %s: %s", versionedRole, err)
return err
}
if err := c.newBuilder.LoadRootForUpdate(raw, v, false); err != nil {
logrus.Debugf("downloaded %s is invalid: %s", versionedRole, err)
return err
}
logrus.Debugf("successfully verified downloaded %s", versionedRole)
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"tufClient",
")",
"updateRootVersions",
"(",
"fromVersion",
",",
"toVersion",
"int",
")",
"error",
"{",
"for",
"v",
":=",
"fromVersion",
";",
"v",
"<=",
"toVersion",
";",
"v",
"++",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"fromVersion",
",",
"toVersion",
",",
"v",
")",
"\n\n",
"versionedRole",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"v",
",",
"data",
".",
"CanonicalRootRole",
")",
"\n\n",
"raw",
",",
"err",
":=",
"c",
".",
"remote",
".",
"GetSized",
"(",
"versionedRole",
",",
"-",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"versionedRole",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"c",
".",
"newBuilder",
".",
"LoadRootForUpdate",
"(",
"raw",
",",
"v",
",",
"false",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"versionedRole",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"versionedRole",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// updateRootVersions updates the root from it's current version to a target, rotating keys
// as they are found
|
[
"updateRootVersions",
"updates",
"the",
"root",
"from",
"it",
"s",
"current",
"version",
"to",
"a",
"target",
"rotating",
"keys",
"as",
"they",
"are",
"found"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/tufclient.go#L142-L160
|
train
|
theupdateframework/notary
|
client/tufclient.go
|
downloadSnapshot
|
func (c *tufClient) downloadSnapshot() error {
logrus.Debug("Loading snapshot...")
role := data.CanonicalSnapshotRole
consistentInfo := c.newBuilder.GetConsistentInfo(role)
_, err := c.tryLoadCacheThenRemote(consistentInfo)
return err
}
|
go
|
func (c *tufClient) downloadSnapshot() error {
logrus.Debug("Loading snapshot...")
role := data.CanonicalSnapshotRole
consistentInfo := c.newBuilder.GetConsistentInfo(role)
_, err := c.tryLoadCacheThenRemote(consistentInfo)
return err
}
|
[
"func",
"(",
"c",
"*",
"tufClient",
")",
"downloadSnapshot",
"(",
")",
"error",
"{",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"role",
":=",
"data",
".",
"CanonicalSnapshotRole",
"\n",
"consistentInfo",
":=",
"c",
".",
"newBuilder",
".",
"GetConsistentInfo",
"(",
"role",
")",
"\n\n",
"_",
",",
"err",
":=",
"c",
".",
"tryLoadCacheThenRemote",
"(",
"consistentInfo",
")",
"\n",
"return",
"err",
"\n",
"}"
] |
// downloadSnapshot is responsible for downloading the snapshot.json
|
[
"downloadSnapshot",
"is",
"responsible",
"for",
"downloading",
"the",
"snapshot",
".",
"json"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/tufclient.go#L201-L208
|
train
|
theupdateframework/notary
|
client/tufclient.go
|
downloadTargets
|
func (c *tufClient) downloadTargets() error {
toDownload := []data.DelegationRole{{
BaseRole: data.BaseRole{Name: data.CanonicalTargetsRole},
Paths: []string{""},
}}
for len(toDownload) > 0 {
role := toDownload[0]
toDownload = toDownload[1:]
consistentInfo := c.newBuilder.GetConsistentInfo(role.Name)
if !consistentInfo.ChecksumKnown() {
logrus.Debugf("skipping %s because there is no checksum for it", role.Name)
continue
}
children, err := c.getTargetsFile(role, consistentInfo)
switch err.(type) {
case signed.ErrExpired, signed.ErrRoleThreshold:
if role.Name == data.CanonicalTargetsRole {
return err
}
logrus.Warnf("Error getting %s: %s", role.Name, err)
break
case nil:
toDownload = append(children, toDownload...)
default:
return err
}
}
return nil
}
|
go
|
func (c *tufClient) downloadTargets() error {
toDownload := []data.DelegationRole{{
BaseRole: data.BaseRole{Name: data.CanonicalTargetsRole},
Paths: []string{""},
}}
for len(toDownload) > 0 {
role := toDownload[0]
toDownload = toDownload[1:]
consistentInfo := c.newBuilder.GetConsistentInfo(role.Name)
if !consistentInfo.ChecksumKnown() {
logrus.Debugf("skipping %s because there is no checksum for it", role.Name)
continue
}
children, err := c.getTargetsFile(role, consistentInfo)
switch err.(type) {
case signed.ErrExpired, signed.ErrRoleThreshold:
if role.Name == data.CanonicalTargetsRole {
return err
}
logrus.Warnf("Error getting %s: %s", role.Name, err)
break
case nil:
toDownload = append(children, toDownload...)
default:
return err
}
}
return nil
}
|
[
"func",
"(",
"c",
"*",
"tufClient",
")",
"downloadTargets",
"(",
")",
"error",
"{",
"toDownload",
":=",
"[",
"]",
"data",
".",
"DelegationRole",
"{",
"{",
"BaseRole",
":",
"data",
".",
"BaseRole",
"{",
"Name",
":",
"data",
".",
"CanonicalTargetsRole",
"}",
",",
"Paths",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
"}",
"\n\n",
"for",
"len",
"(",
"toDownload",
")",
">",
"0",
"{",
"role",
":=",
"toDownload",
"[",
"0",
"]",
"\n",
"toDownload",
"=",
"toDownload",
"[",
"1",
":",
"]",
"\n\n",
"consistentInfo",
":=",
"c",
".",
"newBuilder",
".",
"GetConsistentInfo",
"(",
"role",
".",
"Name",
")",
"\n",
"if",
"!",
"consistentInfo",
".",
"ChecksumKnown",
"(",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"role",
".",
"Name",
")",
"\n",
"continue",
"\n",
"}",
"\n\n",
"children",
",",
"err",
":=",
"c",
".",
"getTargetsFile",
"(",
"role",
",",
"consistentInfo",
")",
"\n",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"signed",
".",
"ErrExpired",
",",
"signed",
".",
"ErrRoleThreshold",
":",
"if",
"role",
".",
"Name",
"==",
"data",
".",
"CanonicalTargetsRole",
"{",
"return",
"err",
"\n",
"}",
"\n",
"logrus",
".",
"Warnf",
"(",
"\"",
"\"",
",",
"role",
".",
"Name",
",",
"err",
")",
"\n",
"break",
"\n",
"case",
"nil",
":",
"toDownload",
"=",
"append",
"(",
"children",
",",
"toDownload",
"...",
")",
"\n",
"default",
":",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// downloadTargets downloads all targets and delegated targets for the repository.
// It uses a pre-order tree traversal as it's necessary to download parents first
// to obtain the keys to validate children.
|
[
"downloadTargets",
"downloads",
"all",
"targets",
"and",
"delegated",
"targets",
"for",
"the",
"repository",
".",
"It",
"uses",
"a",
"pre",
"-",
"order",
"tree",
"traversal",
"as",
"it",
"s",
"necessary",
"to",
"download",
"parents",
"first",
"to",
"obtain",
"the",
"keys",
"to",
"validate",
"children",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/tufclient.go#L213-L244
|
train
|
theupdateframework/notary
|
client/tufclient.go
|
downloadRoot
|
func (c *tufClient) downloadRoot() ([]byte, error) {
role := data.CanonicalRootRole
consistentInfo := c.newBuilder.GetConsistentInfo(role)
// We can't read an exact size for the root metadata without risking getting stuck in the TUF update cycle
// since it's possible that downloading timestamp/snapshot metadata may fail due to a signature mismatch
if !consistentInfo.ChecksumKnown() {
logrus.Debugf("Loading root with no expected checksum")
// get the cached root, if it exists, just for version checking
cachedRoot, _ := c.cache.GetSized(role.String(), -1)
// prefer to download a new root
return c.tryLoadRemote(consistentInfo, cachedRoot)
}
return c.tryLoadCacheThenRemote(consistentInfo)
}
|
go
|
func (c *tufClient) downloadRoot() ([]byte, error) {
role := data.CanonicalRootRole
consistentInfo := c.newBuilder.GetConsistentInfo(role)
// We can't read an exact size for the root metadata without risking getting stuck in the TUF update cycle
// since it's possible that downloading timestamp/snapshot metadata may fail due to a signature mismatch
if !consistentInfo.ChecksumKnown() {
logrus.Debugf("Loading root with no expected checksum")
// get the cached root, if it exists, just for version checking
cachedRoot, _ := c.cache.GetSized(role.String(), -1)
// prefer to download a new root
return c.tryLoadRemote(consistentInfo, cachedRoot)
}
return c.tryLoadCacheThenRemote(consistentInfo)
}
|
[
"func",
"(",
"c",
"*",
"tufClient",
")",
"downloadRoot",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"role",
":=",
"data",
".",
"CanonicalRootRole",
"\n",
"consistentInfo",
":=",
"c",
".",
"newBuilder",
".",
"GetConsistentInfo",
"(",
"role",
")",
"\n\n",
"// We can't read an exact size for the root metadata without risking getting stuck in the TUF update cycle",
"// since it's possible that downloading timestamp/snapshot metadata may fail due to a signature mismatch",
"if",
"!",
"consistentInfo",
".",
"ChecksumKnown",
"(",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n\n",
"// get the cached root, if it exists, just for version checking",
"cachedRoot",
",",
"_",
":=",
"c",
".",
"cache",
".",
"GetSized",
"(",
"role",
".",
"String",
"(",
")",
",",
"-",
"1",
")",
"\n",
"// prefer to download a new root",
"return",
"c",
".",
"tryLoadRemote",
"(",
"consistentInfo",
",",
"cachedRoot",
")",
"\n",
"}",
"\n",
"return",
"c",
".",
"tryLoadCacheThenRemote",
"(",
"consistentInfo",
")",
"\n",
"}"
] |
// downloadRoot is responsible for downloading the root.json
|
[
"downloadRoot",
"is",
"responsible",
"for",
"downloading",
"the",
"root",
".",
"json"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/tufclient.go#L262-L277
|
train
|
theupdateframework/notary
|
client/changelist/change.go
|
NewTUFChange
|
func NewTUFChange(action string, role data.RoleName, changeType, changePath string, content []byte) *TUFChange {
return &TUFChange{
Actn: action,
Role: role,
ChangeType: changeType,
ChangePath: changePath,
Data: content,
}
}
|
go
|
func NewTUFChange(action string, role data.RoleName, changeType, changePath string, content []byte) *TUFChange {
return &TUFChange{
Actn: action,
Role: role,
ChangeType: changeType,
ChangePath: changePath,
Data: content,
}
}
|
[
"func",
"NewTUFChange",
"(",
"action",
"string",
",",
"role",
"data",
".",
"RoleName",
",",
"changeType",
",",
"changePath",
"string",
",",
"content",
"[",
"]",
"byte",
")",
"*",
"TUFChange",
"{",
"return",
"&",
"TUFChange",
"{",
"Actn",
":",
"action",
",",
"Role",
":",
"role",
",",
"ChangeType",
":",
"changeType",
",",
"ChangePath",
":",
"changePath",
",",
"Data",
":",
"content",
",",
"}",
"\n",
"}"
] |
// NewTUFChange initializes a TUFChange object
|
[
"NewTUFChange",
"initializes",
"a",
"TUFChange",
"object"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/changelist/change.go#L45-L53
|
train
|
theupdateframework/notary
|
client/changelist/change.go
|
ToNewRole
|
func (td TUFDelegation) ToNewRole(scope data.RoleName) (*data.Role, error) {
name := scope
if td.NewName != "" {
name = td.NewName
}
return data.NewRole(name, td.NewThreshold, td.AddKeys.IDs(), td.AddPaths)
}
|
go
|
func (td TUFDelegation) ToNewRole(scope data.RoleName) (*data.Role, error) {
name := scope
if td.NewName != "" {
name = td.NewName
}
return data.NewRole(name, td.NewThreshold, td.AddKeys.IDs(), td.AddPaths)
}
|
[
"func",
"(",
"td",
"TUFDelegation",
")",
"ToNewRole",
"(",
"scope",
"data",
".",
"RoleName",
")",
"(",
"*",
"data",
".",
"Role",
",",
"error",
")",
"{",
"name",
":=",
"scope",
"\n",
"if",
"td",
".",
"NewName",
"!=",
"\"",
"\"",
"{",
"name",
"=",
"td",
".",
"NewName",
"\n",
"}",
"\n",
"return",
"data",
".",
"NewRole",
"(",
"name",
",",
"td",
".",
"NewThreshold",
",",
"td",
".",
"AddKeys",
".",
"IDs",
"(",
")",
",",
"td",
".",
"AddPaths",
")",
"\n",
"}"
] |
// ToNewRole creates a fresh role object from the TUFDelegation data
|
[
"ToNewRole",
"creates",
"a",
"fresh",
"role",
"object",
"from",
"the",
"TUFDelegation",
"data"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/client/changelist/change.go#L94-L100
|
train
|
theupdateframework/notary
|
signer/keydbstore/rethink_keydbstore.go
|
NewRethinkDBKeyStore
|
func NewRethinkDBKeyStore(dbName, username, password string, passphraseRetriever notary.PassRetriever, defaultPassAlias string, rethinkSession *gorethink.Session) *RethinkDBKeyStore {
return &RethinkDBKeyStore{
sess: rethinkSession,
defaultPassAlias: defaultPassAlias,
dbName: dbName,
retriever: passphraseRetriever,
user: username,
password: password,
nowFunc: time.Now,
}
}
|
go
|
func NewRethinkDBKeyStore(dbName, username, password string, passphraseRetriever notary.PassRetriever, defaultPassAlias string, rethinkSession *gorethink.Session) *RethinkDBKeyStore {
return &RethinkDBKeyStore{
sess: rethinkSession,
defaultPassAlias: defaultPassAlias,
dbName: dbName,
retriever: passphraseRetriever,
user: username,
password: password,
nowFunc: time.Now,
}
}
|
[
"func",
"NewRethinkDBKeyStore",
"(",
"dbName",
",",
"username",
",",
"password",
"string",
",",
"passphraseRetriever",
"notary",
".",
"PassRetriever",
",",
"defaultPassAlias",
"string",
",",
"rethinkSession",
"*",
"gorethink",
".",
"Session",
")",
"*",
"RethinkDBKeyStore",
"{",
"return",
"&",
"RethinkDBKeyStore",
"{",
"sess",
":",
"rethinkSession",
",",
"defaultPassAlias",
":",
"defaultPassAlias",
",",
"dbName",
":",
"dbName",
",",
"retriever",
":",
"passphraseRetriever",
",",
"user",
":",
"username",
",",
"password",
":",
"password",
",",
"nowFunc",
":",
"time",
".",
"Now",
",",
"}",
"\n",
"}"
] |
// NewRethinkDBKeyStore returns a new RethinkDBKeyStore backed by a RethinkDB database
|
[
"NewRethinkDBKeyStore",
"returns",
"a",
"new",
"RethinkDBKeyStore",
"backed",
"by",
"a",
"RethinkDB",
"database"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/signer/keydbstore/rethink_keydbstore.go#L104-L114
|
train
|
theupdateframework/notary
|
signer/keydbstore/rethink_keydbstore.go
|
getKey
|
func (rdb *RethinkDBKeyStore) getKey(keyID string) (*RDBPrivateKey, string, error) {
// Retrieve the RethinkDB private key from the database
dbPrivateKey := RDBPrivateKey{}
res, err := gorethink.DB(rdb.dbName).Table(dbPrivateKey.TableName()).Filter(gorethink.Row.Field("key_id").Eq(keyID)).Run(rdb.sess)
if err != nil {
return nil, "", err
}
defer res.Close()
err = res.One(&dbPrivateKey)
if err != nil {
return nil, "", trustmanager.ErrKeyNotFound{}
}
// Get the passphrase to use for this key
passphrase, _, err := rdb.retriever(dbPrivateKey.KeyID, dbPrivateKey.PassphraseAlias, false, 1)
if err != nil {
return nil, "", err
}
// Decrypt private bytes from the gorm key
decryptedPrivKey, _, err := jose.Decode(string(dbPrivateKey.Private), passphrase)
if err != nil {
return nil, "", err
}
return &dbPrivateKey, decryptedPrivKey, nil
}
|
go
|
func (rdb *RethinkDBKeyStore) getKey(keyID string) (*RDBPrivateKey, string, error) {
// Retrieve the RethinkDB private key from the database
dbPrivateKey := RDBPrivateKey{}
res, err := gorethink.DB(rdb.dbName).Table(dbPrivateKey.TableName()).Filter(gorethink.Row.Field("key_id").Eq(keyID)).Run(rdb.sess)
if err != nil {
return nil, "", err
}
defer res.Close()
err = res.One(&dbPrivateKey)
if err != nil {
return nil, "", trustmanager.ErrKeyNotFound{}
}
// Get the passphrase to use for this key
passphrase, _, err := rdb.retriever(dbPrivateKey.KeyID, dbPrivateKey.PassphraseAlias, false, 1)
if err != nil {
return nil, "", err
}
// Decrypt private bytes from the gorm key
decryptedPrivKey, _, err := jose.Decode(string(dbPrivateKey.Private), passphrase)
if err != nil {
return nil, "", err
}
return &dbPrivateKey, decryptedPrivKey, nil
}
|
[
"func",
"(",
"rdb",
"*",
"RethinkDBKeyStore",
")",
"getKey",
"(",
"keyID",
"string",
")",
"(",
"*",
"RDBPrivateKey",
",",
"string",
",",
"error",
")",
"{",
"// Retrieve the RethinkDB private key from the database",
"dbPrivateKey",
":=",
"RDBPrivateKey",
"{",
"}",
"\n",
"res",
",",
"err",
":=",
"gorethink",
".",
"DB",
"(",
"rdb",
".",
"dbName",
")",
".",
"Table",
"(",
"dbPrivateKey",
".",
"TableName",
"(",
")",
")",
".",
"Filter",
"(",
"gorethink",
".",
"Row",
".",
"Field",
"(",
"\"",
"\"",
")",
".",
"Eq",
"(",
"keyID",
")",
")",
".",
"Run",
"(",
"rdb",
".",
"sess",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n",
"defer",
"res",
".",
"Close",
"(",
")",
"\n\n",
"err",
"=",
"res",
".",
"One",
"(",
"&",
"dbPrivateKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"trustmanager",
".",
"ErrKeyNotFound",
"{",
"}",
"\n",
"}",
"\n\n",
"// Get the passphrase to use for this key",
"passphrase",
",",
"_",
",",
"err",
":=",
"rdb",
".",
"retriever",
"(",
"dbPrivateKey",
".",
"KeyID",
",",
"dbPrivateKey",
".",
"PassphraseAlias",
",",
"false",
",",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"// Decrypt private bytes from the gorm key",
"decryptedPrivKey",
",",
"_",
",",
"err",
":=",
"jose",
".",
"Decode",
"(",
"string",
"(",
"dbPrivateKey",
".",
"Private",
")",
",",
"passphrase",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"\"",
"\"",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"&",
"dbPrivateKey",
",",
"decryptedPrivKey",
",",
"nil",
"\n",
"}"
] |
// getKeyBytes returns the RDBPrivateKey given a KeyID, as well as the decrypted private bytes
|
[
"getKeyBytes",
"returns",
"the",
"RDBPrivateKey",
"given",
"a",
"KeyID",
"as",
"well",
"as",
"the",
"decrypted",
"private",
"bytes"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/signer/keydbstore/rethink_keydbstore.go#L161-L188
|
train
|
theupdateframework/notary
|
signer/keydbstore/rethink_keydbstore.go
|
GetKey
|
func (rdb *RethinkDBKeyStore) GetKey(keyID string) data.PublicKey {
dbPrivateKey, _, err := rdb.getKey(keyID)
if err != nil {
return nil
}
return data.NewPublicKey(dbPrivateKey.Algorithm, dbPrivateKey.Public)
}
|
go
|
func (rdb *RethinkDBKeyStore) GetKey(keyID string) data.PublicKey {
dbPrivateKey, _, err := rdb.getKey(keyID)
if err != nil {
return nil
}
return data.NewPublicKey(dbPrivateKey.Algorithm, dbPrivateKey.Public)
}
|
[
"func",
"(",
"rdb",
"*",
"RethinkDBKeyStore",
")",
"GetKey",
"(",
"keyID",
"string",
")",
"data",
".",
"PublicKey",
"{",
"dbPrivateKey",
",",
"_",
",",
"err",
":=",
"rdb",
".",
"getKey",
"(",
"keyID",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"data",
".",
"NewPublicKey",
"(",
"dbPrivateKey",
".",
"Algorithm",
",",
"dbPrivateKey",
".",
"Public",
")",
"\n",
"}"
] |
// GetKey returns the PublicKey given a KeyID, and does not activate the key
|
[
"GetKey",
"returns",
"the",
"PublicKey",
"given",
"a",
"KeyID",
"and",
"does",
"not",
"activate",
"the",
"key"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/signer/keydbstore/rethink_keydbstore.go#L209-L216
|
train
|
theupdateframework/notary
|
signer/keydbstore/rethink_keydbstore.go
|
RemoveKey
|
func (rdb RethinkDBKeyStore) RemoveKey(keyID string) error {
// Delete the key from the database
dbPrivateKey := RDBPrivateKey{KeyID: keyID}
_, err := gorethink.DB(rdb.dbName).Table(dbPrivateKey.TableName()).Filter(gorethink.Row.Field("key_id").Eq(keyID)).Delete().RunWrite(rdb.sess)
if err != nil {
return fmt.Errorf("unable to delete private key %s from database: %s", keyID, err.Error())
}
return nil
}
|
go
|
func (rdb RethinkDBKeyStore) RemoveKey(keyID string) error {
// Delete the key from the database
dbPrivateKey := RDBPrivateKey{KeyID: keyID}
_, err := gorethink.DB(rdb.dbName).Table(dbPrivateKey.TableName()).Filter(gorethink.Row.Field("key_id").Eq(keyID)).Delete().RunWrite(rdb.sess)
if err != nil {
return fmt.Errorf("unable to delete private key %s from database: %s", keyID, err.Error())
}
return nil
}
|
[
"func",
"(",
"rdb",
"RethinkDBKeyStore",
")",
"RemoveKey",
"(",
"keyID",
"string",
")",
"error",
"{",
"// Delete the key from the database",
"dbPrivateKey",
":=",
"RDBPrivateKey",
"{",
"KeyID",
":",
"keyID",
"}",
"\n",
"_",
",",
"err",
":=",
"gorethink",
".",
"DB",
"(",
"rdb",
".",
"dbName",
")",
".",
"Table",
"(",
"dbPrivateKey",
".",
"TableName",
"(",
")",
")",
".",
"Filter",
"(",
"gorethink",
".",
"Row",
".",
"Field",
"(",
"\"",
"\"",
")",
".",
"Eq",
"(",
"keyID",
")",
")",
".",
"Delete",
"(",
")",
".",
"RunWrite",
"(",
"rdb",
".",
"sess",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"keyID",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// RemoveKey removes the key from the table
|
[
"RemoveKey",
"removes",
"the",
"key",
"from",
"the",
"table"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/signer/keydbstore/rethink_keydbstore.go#L229-L238
|
train
|
theupdateframework/notary
|
signer/keydbstore/rethink_keydbstore.go
|
Bootstrap
|
func (rdb RethinkDBKeyStore) Bootstrap() error {
if err := rethinkdb.SetupDB(rdb.sess, rdb.dbName, []rethinkdb.Table{
PrivateKeysRethinkTable,
}); err != nil {
return err
}
return rethinkdb.CreateAndGrantDBUser(rdb.sess, rdb.dbName, rdb.user, rdb.password)
}
|
go
|
func (rdb RethinkDBKeyStore) Bootstrap() error {
if err := rethinkdb.SetupDB(rdb.sess, rdb.dbName, []rethinkdb.Table{
PrivateKeysRethinkTable,
}); err != nil {
return err
}
return rethinkdb.CreateAndGrantDBUser(rdb.sess, rdb.dbName, rdb.user, rdb.password)
}
|
[
"func",
"(",
"rdb",
"RethinkDBKeyStore",
")",
"Bootstrap",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"rethinkdb",
".",
"SetupDB",
"(",
"rdb",
".",
"sess",
",",
"rdb",
".",
"dbName",
",",
"[",
"]",
"rethinkdb",
".",
"Table",
"{",
"PrivateKeysRethinkTable",
",",
"}",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"return",
"rethinkdb",
".",
"CreateAndGrantDBUser",
"(",
"rdb",
".",
"sess",
",",
"rdb",
".",
"dbName",
",",
"rdb",
".",
"user",
",",
"rdb",
".",
"password",
")",
"\n",
"}"
] |
// Bootstrap sets up the database and tables, also creating the notary signer user with appropriate db permission
|
[
"Bootstrap",
"sets",
"up",
"the",
"database",
"and",
"tables",
"also",
"creating",
"the",
"notary",
"signer",
"user",
"with",
"appropriate",
"db",
"permission"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/signer/keydbstore/rethink_keydbstore.go#L310-L317
|
train
|
theupdateframework/notary
|
tuf/signed/verify.go
|
VerifyExpiry
|
func VerifyExpiry(s *data.SignedCommon, role data.RoleName) error {
if IsExpired(s.Expires) {
logrus.Errorf("Metadata for %s expired", role)
return ErrExpired{Role: role, Expired: s.Expires.Format("Mon Jan 2 15:04:05 MST 2006")}
}
return nil
}
|
go
|
func VerifyExpiry(s *data.SignedCommon, role data.RoleName) error {
if IsExpired(s.Expires) {
logrus.Errorf("Metadata for %s expired", role)
return ErrExpired{Role: role, Expired: s.Expires.Format("Mon Jan 2 15:04:05 MST 2006")}
}
return nil
}
|
[
"func",
"VerifyExpiry",
"(",
"s",
"*",
"data",
".",
"SignedCommon",
",",
"role",
"data",
".",
"RoleName",
")",
"error",
"{",
"if",
"IsExpired",
"(",
"s",
".",
"Expires",
")",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"role",
")",
"\n",
"return",
"ErrExpired",
"{",
"Role",
":",
"role",
",",
"Expired",
":",
"s",
".",
"Expires",
".",
"Format",
"(",
"\"",
"\"",
")",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// VerifyExpiry returns ErrExpired if the metadata is expired
|
[
"VerifyExpiry",
"returns",
"ErrExpired",
"if",
"the",
"metadata",
"is",
"expired"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verify.go#L28-L34
|
train
|
theupdateframework/notary
|
tuf/signed/verify.go
|
VerifyVersion
|
func VerifyVersion(s *data.SignedCommon, minVersion int) error {
if s.Version < minVersion {
return ErrLowVersion{Actual: s.Version, Current: minVersion}
}
return nil
}
|
go
|
func VerifyVersion(s *data.SignedCommon, minVersion int) error {
if s.Version < minVersion {
return ErrLowVersion{Actual: s.Version, Current: minVersion}
}
return nil
}
|
[
"func",
"VerifyVersion",
"(",
"s",
"*",
"data",
".",
"SignedCommon",
",",
"minVersion",
"int",
")",
"error",
"{",
"if",
"s",
".",
"Version",
"<",
"minVersion",
"{",
"return",
"ErrLowVersion",
"{",
"Actual",
":",
"s",
".",
"Version",
",",
"Current",
":",
"minVersion",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// VerifyVersion returns ErrLowVersion if the metadata version is lower than the min version
|
[
"VerifyVersion",
"returns",
"ErrLowVersion",
"if",
"the",
"metadata",
"version",
"is",
"lower",
"than",
"the",
"min",
"version"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verify.go#L37-L42
|
train
|
theupdateframework/notary
|
tuf/signed/verify.go
|
VerifySignatures
|
func VerifySignatures(s *data.Signed, roleData data.BaseRole) error {
if len(s.Signatures) == 0 {
return ErrNoSignatures
}
if roleData.Threshold < 1 {
return ErrRoleThreshold{}
}
logrus.Debugf("%s role has key IDs: %s", roleData.Name, strings.Join(roleData.ListKeyIDs(), ","))
// remarshal the signed part so we can verify the signature, since the signature has
// to be of a canonically marshalled signed object
var decoded map[string]interface{}
if err := json.Unmarshal(*s.Signed, &decoded); err != nil {
return err
}
msg, err := json.MarshalCanonical(decoded)
if err != nil {
return err
}
valid := make(map[string]struct{})
for i := range s.Signatures {
sig := &(s.Signatures[i])
logrus.Debug("verifying signature for key ID: ", sig.KeyID)
key, ok := roleData.Keys[sig.KeyID]
if !ok {
logrus.Debugf("continuing b/c keyid lookup was nil: %s\n", sig.KeyID)
continue
}
// Check that the signature key ID actually matches the content ID of the key
if key.ID() != sig.KeyID {
return ErrInvalidKeyID{}
}
if err := VerifySignature(msg, sig, key); err != nil {
logrus.Debugf("continuing b/c %s", err.Error())
continue
}
valid[sig.KeyID] = struct{}{}
}
if len(valid) < roleData.Threshold {
return ErrRoleThreshold{
Msg: fmt.Sprintf("valid signatures did not meet threshold for %s", roleData.Name),
}
}
return nil
}
|
go
|
func VerifySignatures(s *data.Signed, roleData data.BaseRole) error {
if len(s.Signatures) == 0 {
return ErrNoSignatures
}
if roleData.Threshold < 1 {
return ErrRoleThreshold{}
}
logrus.Debugf("%s role has key IDs: %s", roleData.Name, strings.Join(roleData.ListKeyIDs(), ","))
// remarshal the signed part so we can verify the signature, since the signature has
// to be of a canonically marshalled signed object
var decoded map[string]interface{}
if err := json.Unmarshal(*s.Signed, &decoded); err != nil {
return err
}
msg, err := json.MarshalCanonical(decoded)
if err != nil {
return err
}
valid := make(map[string]struct{})
for i := range s.Signatures {
sig := &(s.Signatures[i])
logrus.Debug("verifying signature for key ID: ", sig.KeyID)
key, ok := roleData.Keys[sig.KeyID]
if !ok {
logrus.Debugf("continuing b/c keyid lookup was nil: %s\n", sig.KeyID)
continue
}
// Check that the signature key ID actually matches the content ID of the key
if key.ID() != sig.KeyID {
return ErrInvalidKeyID{}
}
if err := VerifySignature(msg, sig, key); err != nil {
logrus.Debugf("continuing b/c %s", err.Error())
continue
}
valid[sig.KeyID] = struct{}{}
}
if len(valid) < roleData.Threshold {
return ErrRoleThreshold{
Msg: fmt.Sprintf("valid signatures did not meet threshold for %s", roleData.Name),
}
}
return nil
}
|
[
"func",
"VerifySignatures",
"(",
"s",
"*",
"data",
".",
"Signed",
",",
"roleData",
"data",
".",
"BaseRole",
")",
"error",
"{",
"if",
"len",
"(",
"s",
".",
"Signatures",
")",
"==",
"0",
"{",
"return",
"ErrNoSignatures",
"\n",
"}",
"\n\n",
"if",
"roleData",
".",
"Threshold",
"<",
"1",
"{",
"return",
"ErrRoleThreshold",
"{",
"}",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"roleData",
".",
"Name",
",",
"strings",
".",
"Join",
"(",
"roleData",
".",
"ListKeyIDs",
"(",
")",
",",
"\"",
"\"",
")",
")",
"\n\n",
"// remarshal the signed part so we can verify the signature, since the signature has",
"// to be of a canonically marshalled signed object",
"var",
"decoded",
"map",
"[",
"string",
"]",
"interface",
"{",
"}",
"\n",
"if",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"*",
"s",
".",
"Signed",
",",
"&",
"decoded",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"msg",
",",
"err",
":=",
"json",
".",
"MarshalCanonical",
"(",
"decoded",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"valid",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"struct",
"{",
"}",
")",
"\n",
"for",
"i",
":=",
"range",
"s",
".",
"Signatures",
"{",
"sig",
":=",
"&",
"(",
"s",
".",
"Signatures",
"[",
"i",
"]",
")",
"\n",
"logrus",
".",
"Debug",
"(",
"\"",
"\"",
",",
"sig",
".",
"KeyID",
")",
"\n",
"key",
",",
"ok",
":=",
"roleData",
".",
"Keys",
"[",
"sig",
".",
"KeyID",
"]",
"\n",
"if",
"!",
"ok",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\\n",
"\"",
",",
"sig",
".",
"KeyID",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"// Check that the signature key ID actually matches the content ID of the key",
"if",
"key",
".",
"ID",
"(",
")",
"!=",
"sig",
".",
"KeyID",
"{",
"return",
"ErrInvalidKeyID",
"{",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"VerifySignature",
"(",
"msg",
",",
"sig",
",",
"key",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"continue",
"\n",
"}",
"\n",
"valid",
"[",
"sig",
".",
"KeyID",
"]",
"=",
"struct",
"{",
"}",
"{",
"}",
"\n",
"}",
"\n",
"if",
"len",
"(",
"valid",
")",
"<",
"roleData",
".",
"Threshold",
"{",
"return",
"ErrRoleThreshold",
"{",
"Msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"roleData",
".",
"Name",
")",
",",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// VerifySignatures checks the we have sufficient valid signatures for the given role
|
[
"VerifySignatures",
"checks",
"the",
"we",
"have",
"sufficient",
"valid",
"signatures",
"for",
"the",
"given",
"role"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verify.go#L45-L92
|
train
|
theupdateframework/notary
|
tuf/signed/verify.go
|
VerifySignature
|
func VerifySignature(msg []byte, sig *data.Signature, pk data.PublicKey) error {
// method lookup is consistent due to Unmarshal JSON doing lower case for us.
method := sig.Method
verifier, ok := Verifiers[method]
if !ok {
return fmt.Errorf("signing method is not supported: %s", sig.Method)
}
if err := verifier.Verify(pk, sig.Signature, msg); err != nil {
return fmt.Errorf("signature was invalid")
}
sig.IsValid = true
return nil
}
|
go
|
func VerifySignature(msg []byte, sig *data.Signature, pk data.PublicKey) error {
// method lookup is consistent due to Unmarshal JSON doing lower case for us.
method := sig.Method
verifier, ok := Verifiers[method]
if !ok {
return fmt.Errorf("signing method is not supported: %s", sig.Method)
}
if err := verifier.Verify(pk, sig.Signature, msg); err != nil {
return fmt.Errorf("signature was invalid")
}
sig.IsValid = true
return nil
}
|
[
"func",
"VerifySignature",
"(",
"msg",
"[",
"]",
"byte",
",",
"sig",
"*",
"data",
".",
"Signature",
",",
"pk",
"data",
".",
"PublicKey",
")",
"error",
"{",
"// method lookup is consistent due to Unmarshal JSON doing lower case for us.",
"method",
":=",
"sig",
".",
"Method",
"\n",
"verifier",
",",
"ok",
":=",
"Verifiers",
"[",
"method",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"sig",
".",
"Method",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"verifier",
".",
"Verify",
"(",
"pk",
",",
"sig",
".",
"Signature",
",",
"msg",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"sig",
".",
"IsValid",
"=",
"true",
"\n",
"return",
"nil",
"\n",
"}"
] |
// VerifySignature checks a single signature and public key against a payload
// If the signature is verified, the signature's is valid field will actually
// be mutated to be equal to the boolean true
|
[
"VerifySignature",
"checks",
"a",
"single",
"signature",
"and",
"public",
"key",
"against",
"a",
"payload",
"If",
"the",
"signature",
"is",
"verified",
"the",
"signature",
"s",
"is",
"valid",
"field",
"will",
"actually",
"be",
"mutated",
"to",
"be",
"equal",
"to",
"the",
"boolean",
"true"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verify.go#L97-L110
|
train
|
theupdateframework/notary
|
tuf/signed/verify.go
|
VerifyPublicKeyMatchesPrivateKey
|
func VerifyPublicKeyMatchesPrivateKey(privKey data.PrivateKey, pubKey data.PublicKey) error {
pubKeyID, err := utils.CanonicalKeyID(pubKey)
if err != nil {
return fmt.Errorf("could not verify key pair: %v", err)
}
if privKey == nil || pubKeyID != privKey.ID() {
return fmt.Errorf("private key is nil or does not match public key")
}
return nil
}
|
go
|
func VerifyPublicKeyMatchesPrivateKey(privKey data.PrivateKey, pubKey data.PublicKey) error {
pubKeyID, err := utils.CanonicalKeyID(pubKey)
if err != nil {
return fmt.Errorf("could not verify key pair: %v", err)
}
if privKey == nil || pubKeyID != privKey.ID() {
return fmt.Errorf("private key is nil or does not match public key")
}
return nil
}
|
[
"func",
"VerifyPublicKeyMatchesPrivateKey",
"(",
"privKey",
"data",
".",
"PrivateKey",
",",
"pubKey",
"data",
".",
"PublicKey",
")",
"error",
"{",
"pubKeyID",
",",
"err",
":=",
"utils",
".",
"CanonicalKeyID",
"(",
"pubKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"privKey",
"==",
"nil",
"||",
"pubKeyID",
"!=",
"privKey",
".",
"ID",
"(",
")",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// VerifyPublicKeyMatchesPrivateKey checks if the private key and the public keys forms valid key pairs.
// Supports both x509 certificate PublicKeys and non-certificate PublicKeys
|
[
"VerifyPublicKeyMatchesPrivateKey",
"checks",
"if",
"the",
"private",
"key",
"and",
"the",
"public",
"keys",
"forms",
"valid",
"key",
"pairs",
".",
"Supports",
"both",
"x509",
"certificate",
"PublicKeys",
"and",
"non",
"-",
"certificate",
"PublicKeys"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verify.go#L114-L123
|
train
|
theupdateframework/notary
|
cmd/notary/repo_factory.go
|
ConfigureRepo
|
func ConfigureRepo(v *viper.Viper, retriever notary.PassRetriever, onlineOperation bool, permission httpAccess) RepoFactory {
localRepo := func(gun data.GUN) (client.Repository, error) {
var rt http.RoundTripper
trustPin, err := getTrustPinning(v)
if err != nil {
return nil, err
}
if onlineOperation {
rt, err = getTransport(v, gun, permission)
if err != nil {
return nil, err
}
}
return client.NewFileCachedRepository(
v.GetString("trust_dir"),
gun,
getRemoteTrustServer(v),
rt,
retriever,
trustPin,
)
}
return localRepo
}
|
go
|
func ConfigureRepo(v *viper.Viper, retriever notary.PassRetriever, onlineOperation bool, permission httpAccess) RepoFactory {
localRepo := func(gun data.GUN) (client.Repository, error) {
var rt http.RoundTripper
trustPin, err := getTrustPinning(v)
if err != nil {
return nil, err
}
if onlineOperation {
rt, err = getTransport(v, gun, permission)
if err != nil {
return nil, err
}
}
return client.NewFileCachedRepository(
v.GetString("trust_dir"),
gun,
getRemoteTrustServer(v),
rt,
retriever,
trustPin,
)
}
return localRepo
}
|
[
"func",
"ConfigureRepo",
"(",
"v",
"*",
"viper",
".",
"Viper",
",",
"retriever",
"notary",
".",
"PassRetriever",
",",
"onlineOperation",
"bool",
",",
"permission",
"httpAccess",
")",
"RepoFactory",
"{",
"localRepo",
":=",
"func",
"(",
"gun",
"data",
".",
"GUN",
")",
"(",
"client",
".",
"Repository",
",",
"error",
")",
"{",
"var",
"rt",
"http",
".",
"RoundTripper",
"\n",
"trustPin",
",",
"err",
":=",
"getTrustPinning",
"(",
"v",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"onlineOperation",
"{",
"rt",
",",
"err",
"=",
"getTransport",
"(",
"v",
",",
"gun",
",",
"permission",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"client",
".",
"NewFileCachedRepository",
"(",
"v",
".",
"GetString",
"(",
"\"",
"\"",
")",
",",
"gun",
",",
"getRemoteTrustServer",
"(",
"v",
")",
",",
"rt",
",",
"retriever",
",",
"trustPin",
",",
")",
"\n",
"}",
"\n\n",
"return",
"localRepo",
"\n",
"}"
] |
// ConfigureRepo takes in the configuration parameters and returns a repoFactory that can
// initialize new client.Repository objects with the correct upstreams and password
// retrieval mechanisms.
|
[
"ConfigureRepo",
"takes",
"in",
"the",
"configuration",
"parameters",
"and",
"returns",
"a",
"repoFactory",
"that",
"can",
"initialize",
"new",
"client",
".",
"Repository",
"objects",
"with",
"the",
"correct",
"upstreams",
"and",
"password",
"retrieval",
"mechanisms",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/cmd/notary/repo_factory.go#L21-L45
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
SetYubikeyKeyMode
|
func SetYubikeyKeyMode(keyMode int) error {
// technically 7 (1 | 2 | 4) is valid, but KeymodePinOnce +
// KeymdoePinAlways don't really make sense together
if keyMode < 0 || keyMode > 5 {
return errors.New("Invalid key mode")
}
yubikeyKeymode = keyMode
return nil
}
|
go
|
func SetYubikeyKeyMode(keyMode int) error {
// technically 7 (1 | 2 | 4) is valid, but KeymodePinOnce +
// KeymdoePinAlways don't really make sense together
if keyMode < 0 || keyMode > 5 {
return errors.New("Invalid key mode")
}
yubikeyKeymode = keyMode
return nil
}
|
[
"func",
"SetYubikeyKeyMode",
"(",
"keyMode",
"int",
")",
"error",
"{",
"// technically 7 (1 | 2 | 4) is valid, but KeymodePinOnce +",
"// KeymdoePinAlways don't really make sense together",
"if",
"keyMode",
"<",
"0",
"||",
"keyMode",
">",
"5",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"yubikeyKeymode",
"=",
"keyMode",
"\n",
"return",
"nil",
"\n",
"}"
] |
// SetYubikeyKeyMode - sets the mode when generating yubikey keys.
// This is to be used for testing. It does nothing if not building with tag
// pkcs11.
|
[
"SetYubikeyKeyMode",
"-",
"sets",
"the",
"mode",
"when",
"generating",
"yubikey",
"keys",
".",
"This",
"is",
"to",
"be",
"used",
"for",
"testing",
".",
"It",
"does",
"nothing",
"if",
"not",
"building",
"with",
"tag",
"pkcs11",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L63-L71
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
NewYubiPrivateKey
|
func NewYubiPrivateKey(slot []byte, pubKey data.ECDSAPublicKey,
passRetriever notary.PassRetriever) *YubiPrivateKey {
return &YubiPrivateKey{
ECDSAPublicKey: pubKey,
passRetriever: passRetriever,
slot: slot,
libLoader: defaultLoader,
}
}
|
go
|
func NewYubiPrivateKey(slot []byte, pubKey data.ECDSAPublicKey,
passRetriever notary.PassRetriever) *YubiPrivateKey {
return &YubiPrivateKey{
ECDSAPublicKey: pubKey,
passRetriever: passRetriever,
slot: slot,
libLoader: defaultLoader,
}
}
|
[
"func",
"NewYubiPrivateKey",
"(",
"slot",
"[",
"]",
"byte",
",",
"pubKey",
"data",
".",
"ECDSAPublicKey",
",",
"passRetriever",
"notary",
".",
"PassRetriever",
")",
"*",
"YubiPrivateKey",
"{",
"return",
"&",
"YubiPrivateKey",
"{",
"ECDSAPublicKey",
":",
"pubKey",
",",
"passRetriever",
":",
"passRetriever",
",",
"slot",
":",
"slot",
",",
"libLoader",
":",
"defaultLoader",
",",
"}",
"\n",
"}"
] |
// NewYubiPrivateKey returns a YubiPrivateKey, which implements the data.PrivateKey
// interface except that the private material is inaccessible
|
[
"NewYubiPrivateKey",
"returns",
"a",
"YubiPrivateKey",
"which",
"implements",
"the",
"data",
".",
"PrivateKey",
"interface",
"except",
"that",
"the",
"private",
"material",
"is",
"inaccessible"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L148-L157
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
Public
|
func (ys *yubikeySigner) Public() crypto.PublicKey {
publicKey, err := x509.ParsePKIXPublicKey(ys.YubiPrivateKey.Public())
if err != nil {
return nil
}
return publicKey
}
|
go
|
func (ys *yubikeySigner) Public() crypto.PublicKey {
publicKey, err := x509.ParsePKIXPublicKey(ys.YubiPrivateKey.Public())
if err != nil {
return nil
}
return publicKey
}
|
[
"func",
"(",
"ys",
"*",
"yubikeySigner",
")",
"Public",
"(",
")",
"crypto",
".",
"PublicKey",
"{",
"publicKey",
",",
"err",
":=",
"x509",
".",
"ParsePKIXPublicKey",
"(",
"ys",
".",
"YubiPrivateKey",
".",
"Public",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
"\n",
"}",
"\n\n",
"return",
"publicKey",
"\n",
"}"
] |
// Public is a required method of the crypto.Signer interface
|
[
"Public",
"is",
"a",
"required",
"method",
"of",
"the",
"crypto",
".",
"Signer",
"interface"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L160-L167
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
Sign
|
func (y *YubiPrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error) {
ctx, session, err := SetupHSMEnv(pkcs11Lib, y.libLoader)
if err != nil {
return nil, err
}
defer cleanup(ctx, session)
v := signed.Verifiers[data.ECDSASignature]
for i := 0; i < sigAttempts; i++ {
sig, err := sign(ctx, session, y.slot, y.passRetriever, msg)
if err != nil {
return nil, fmt.Errorf("failed to sign using Yubikey: %v", err)
}
if err := v.Verify(&y.ECDSAPublicKey, sig, msg); err == nil {
return sig, nil
}
}
return nil, errors.New("failed to generate signature on Yubikey")
}
|
go
|
func (y *YubiPrivateKey) Sign(rand io.Reader, msg []byte, opts crypto.SignerOpts) ([]byte, error) {
ctx, session, err := SetupHSMEnv(pkcs11Lib, y.libLoader)
if err != nil {
return nil, err
}
defer cleanup(ctx, session)
v := signed.Verifiers[data.ECDSASignature]
for i := 0; i < sigAttempts; i++ {
sig, err := sign(ctx, session, y.slot, y.passRetriever, msg)
if err != nil {
return nil, fmt.Errorf("failed to sign using Yubikey: %v", err)
}
if err := v.Verify(&y.ECDSAPublicKey, sig, msg); err == nil {
return sig, nil
}
}
return nil, errors.New("failed to generate signature on Yubikey")
}
|
[
"func",
"(",
"y",
"*",
"YubiPrivateKey",
")",
"Sign",
"(",
"rand",
"io",
".",
"Reader",
",",
"msg",
"[",
"]",
"byte",
",",
"opts",
"crypto",
".",
"SignerOpts",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"ctx",
",",
"session",
",",
"err",
":=",
"SetupHSMEnv",
"(",
"pkcs11Lib",
",",
"y",
".",
"libLoader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"defer",
"cleanup",
"(",
"ctx",
",",
"session",
")",
"\n\n",
"v",
":=",
"signed",
".",
"Verifiers",
"[",
"data",
".",
"ECDSASignature",
"]",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"sigAttempts",
";",
"i",
"++",
"{",
"sig",
",",
"err",
":=",
"sign",
"(",
"ctx",
",",
"session",
",",
"y",
".",
"slot",
",",
"y",
".",
"passRetriever",
",",
"msg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"if",
"err",
":=",
"v",
".",
"Verify",
"(",
"&",
"y",
".",
"ECDSAPublicKey",
",",
"sig",
",",
"msg",
")",
";",
"err",
"==",
"nil",
"{",
"return",
"sig",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// Sign is a required method of the crypto.Signer interface and the data.PrivateKey
// interface
|
[
"Sign",
"is",
"a",
"required",
"method",
"of",
"the",
"crypto",
".",
"Signer",
"interface",
"and",
"the",
"data",
".",
"PrivateKey",
"interface"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L194-L212
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
ensurePrivateKeySize
|
func ensurePrivateKeySize(payload []byte) []byte {
final := payload
if len(payload) < ecdsaPrivateKeySize {
final = make([]byte, ecdsaPrivateKeySize)
copy(final[ecdsaPrivateKeySize-len(payload):], payload)
}
return final
}
|
go
|
func ensurePrivateKeySize(payload []byte) []byte {
final := payload
if len(payload) < ecdsaPrivateKeySize {
final = make([]byte, ecdsaPrivateKeySize)
copy(final[ecdsaPrivateKeySize-len(payload):], payload)
}
return final
}
|
[
"func",
"ensurePrivateKeySize",
"(",
"payload",
"[",
"]",
"byte",
")",
"[",
"]",
"byte",
"{",
"final",
":=",
"payload",
"\n",
"if",
"len",
"(",
"payload",
")",
"<",
"ecdsaPrivateKeySize",
"{",
"final",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"ecdsaPrivateKeySize",
")",
"\n",
"copy",
"(",
"final",
"[",
"ecdsaPrivateKeySize",
"-",
"len",
"(",
"payload",
")",
":",
"]",
",",
"payload",
")",
"\n",
"}",
"\n",
"return",
"final",
"\n",
"}"
] |
// If a byte array is less than the number of bytes specified by
// ecdsaPrivateKeySize, left-zero-pad the byte array until
// it is the required size.
|
[
"If",
"a",
"byte",
"array",
"is",
"less",
"than",
"the",
"number",
"of",
"bytes",
"specified",
"by",
"ecdsaPrivateKeySize",
"left",
"-",
"zero",
"-",
"pad",
"the",
"byte",
"array",
"until",
"it",
"is",
"the",
"required",
"size",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L217-L224
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
addECDSAKey
|
func addECDSAKey(
ctx IPKCS11Ctx,
session pkcs11.SessionHandle,
privKey data.PrivateKey,
pkcs11KeyID []byte,
passRetriever notary.PassRetriever,
role data.RoleName,
) error {
logrus.Debugf("Attempting to add key to yubikey with ID: %s", privKey.ID())
err := login(ctx, session, passRetriever, pkcs11.CKU_SO, SOUserPin)
if err != nil {
return err
}
defer ctx.Logout(session)
// Create an ecdsa.PrivateKey out of the private key bytes
ecdsaPrivKey, err := x509.ParseECPrivateKey(privKey.Private())
if err != nil {
return err
}
ecdsaPrivKeyD := ensurePrivateKeySize(ecdsaPrivKey.D.Bytes())
// Hard-coded policy: the generated certificate expires in 10 years.
startTime := time.Now()
template, err := utils.NewCertificate(role.String(), startTime, startTime.AddDate(10, 0, 0))
if err != nil {
return fmt.Errorf("failed to create the certificate template: %v", err)
}
certBytes, err := x509.CreateCertificate(rand.Reader, template, template, ecdsaPrivKey.Public(), ecdsaPrivKey)
if err != nil {
return fmt.Errorf("failed to create the certificate: %v", err)
}
certTemplate := []*pkcs11.Attribute{
pkcs11.NewAttribute(pkcs11.CKA_CLASS, pkcs11.CKO_CERTIFICATE),
pkcs11.NewAttribute(pkcs11.CKA_VALUE, certBytes),
pkcs11.NewAttribute(pkcs11.CKA_ID, pkcs11KeyID),
}
privateKeyTemplate := []*pkcs11.Attribute{
pkcs11.NewAttribute(pkcs11.CKA_CLASS, pkcs11.CKO_PRIVATE_KEY),
pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, pkcs11.CKK_ECDSA),
pkcs11.NewAttribute(pkcs11.CKA_ID, pkcs11KeyID),
pkcs11.NewAttribute(pkcs11.CKA_EC_PARAMS, []byte{0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07}),
pkcs11.NewAttribute(pkcs11.CKA_VALUE, ecdsaPrivKeyD),
pkcs11.NewAttribute(pkcs11.CKA_VENDOR_DEFINED, yubikeyKeymode),
}
_, err = ctx.CreateObject(session, certTemplate)
if err != nil {
return fmt.Errorf("error importing: %v", err)
}
_, err = ctx.CreateObject(session, privateKeyTemplate)
if err != nil {
return fmt.Errorf("error importing: %v", err)
}
return nil
}
|
go
|
func addECDSAKey(
ctx IPKCS11Ctx,
session pkcs11.SessionHandle,
privKey data.PrivateKey,
pkcs11KeyID []byte,
passRetriever notary.PassRetriever,
role data.RoleName,
) error {
logrus.Debugf("Attempting to add key to yubikey with ID: %s", privKey.ID())
err := login(ctx, session, passRetriever, pkcs11.CKU_SO, SOUserPin)
if err != nil {
return err
}
defer ctx.Logout(session)
// Create an ecdsa.PrivateKey out of the private key bytes
ecdsaPrivKey, err := x509.ParseECPrivateKey(privKey.Private())
if err != nil {
return err
}
ecdsaPrivKeyD := ensurePrivateKeySize(ecdsaPrivKey.D.Bytes())
// Hard-coded policy: the generated certificate expires in 10 years.
startTime := time.Now()
template, err := utils.NewCertificate(role.String(), startTime, startTime.AddDate(10, 0, 0))
if err != nil {
return fmt.Errorf("failed to create the certificate template: %v", err)
}
certBytes, err := x509.CreateCertificate(rand.Reader, template, template, ecdsaPrivKey.Public(), ecdsaPrivKey)
if err != nil {
return fmt.Errorf("failed to create the certificate: %v", err)
}
certTemplate := []*pkcs11.Attribute{
pkcs11.NewAttribute(pkcs11.CKA_CLASS, pkcs11.CKO_CERTIFICATE),
pkcs11.NewAttribute(pkcs11.CKA_VALUE, certBytes),
pkcs11.NewAttribute(pkcs11.CKA_ID, pkcs11KeyID),
}
privateKeyTemplate := []*pkcs11.Attribute{
pkcs11.NewAttribute(pkcs11.CKA_CLASS, pkcs11.CKO_PRIVATE_KEY),
pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, pkcs11.CKK_ECDSA),
pkcs11.NewAttribute(pkcs11.CKA_ID, pkcs11KeyID),
pkcs11.NewAttribute(pkcs11.CKA_EC_PARAMS, []byte{0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07}),
pkcs11.NewAttribute(pkcs11.CKA_VALUE, ecdsaPrivKeyD),
pkcs11.NewAttribute(pkcs11.CKA_VENDOR_DEFINED, yubikeyKeymode),
}
_, err = ctx.CreateObject(session, certTemplate)
if err != nil {
return fmt.Errorf("error importing: %v", err)
}
_, err = ctx.CreateObject(session, privateKeyTemplate)
if err != nil {
return fmt.Errorf("error importing: %v", err)
}
return nil
}
|
[
"func",
"addECDSAKey",
"(",
"ctx",
"IPKCS11Ctx",
",",
"session",
"pkcs11",
".",
"SessionHandle",
",",
"privKey",
"data",
".",
"PrivateKey",
",",
"pkcs11KeyID",
"[",
"]",
"byte",
",",
"passRetriever",
"notary",
".",
"PassRetriever",
",",
"role",
"data",
".",
"RoleName",
",",
")",
"error",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"privKey",
".",
"ID",
"(",
")",
")",
"\n\n",
"err",
":=",
"login",
"(",
"ctx",
",",
"session",
",",
"passRetriever",
",",
"pkcs11",
".",
"CKU_SO",
",",
"SOUserPin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"defer",
"ctx",
".",
"Logout",
"(",
"session",
")",
"\n\n",
"// Create an ecdsa.PrivateKey out of the private key bytes",
"ecdsaPrivKey",
",",
"err",
":=",
"x509",
".",
"ParseECPrivateKey",
"(",
"privKey",
".",
"Private",
"(",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"ecdsaPrivKeyD",
":=",
"ensurePrivateKeySize",
"(",
"ecdsaPrivKey",
".",
"D",
".",
"Bytes",
"(",
")",
")",
"\n\n",
"// Hard-coded policy: the generated certificate expires in 10 years.",
"startTime",
":=",
"time",
".",
"Now",
"(",
")",
"\n",
"template",
",",
"err",
":=",
"utils",
".",
"NewCertificate",
"(",
"role",
".",
"String",
"(",
")",
",",
"startTime",
",",
"startTime",
".",
"AddDate",
"(",
"10",
",",
"0",
",",
"0",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"certBytes",
",",
"err",
":=",
"x509",
".",
"CreateCertificate",
"(",
"rand",
".",
"Reader",
",",
"template",
",",
"template",
",",
"ecdsaPrivKey",
".",
"Public",
"(",
")",
",",
"ecdsaPrivKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"certTemplate",
":=",
"[",
"]",
"*",
"pkcs11",
".",
"Attribute",
"{",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_CLASS",
",",
"pkcs11",
".",
"CKO_CERTIFICATE",
")",
",",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_VALUE",
",",
"certBytes",
")",
",",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_ID",
",",
"pkcs11KeyID",
")",
",",
"}",
"\n\n",
"privateKeyTemplate",
":=",
"[",
"]",
"*",
"pkcs11",
".",
"Attribute",
"{",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_CLASS",
",",
"pkcs11",
".",
"CKO_PRIVATE_KEY",
")",
",",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_KEY_TYPE",
",",
"pkcs11",
".",
"CKK_ECDSA",
")",
",",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_ID",
",",
"pkcs11KeyID",
")",
",",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_EC_PARAMS",
",",
"[",
"]",
"byte",
"{",
"0x06",
",",
"0x08",
",",
"0x2a",
",",
"0x86",
",",
"0x48",
",",
"0xce",
",",
"0x3d",
",",
"0x03",
",",
"0x01",
",",
"0x07",
"}",
")",
",",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_VALUE",
",",
"ecdsaPrivKeyD",
")",
",",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_VENDOR_DEFINED",
",",
"yubikeyKeymode",
")",
",",
"}",
"\n\n",
"_",
",",
"err",
"=",
"ctx",
".",
"CreateObject",
"(",
"session",
",",
"certTemplate",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"_",
",",
"err",
"=",
"ctx",
".",
"CreateObject",
"(",
"session",
",",
"privateKeyTemplate",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// addECDSAKey adds a key to the yubikey
|
[
"addECDSAKey",
"adds",
"a",
"key",
"to",
"the",
"yubikey"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L227-L289
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
sign
|
func sign(ctx IPKCS11Ctx, session pkcs11.SessionHandle, pkcs11KeyID []byte, passRetriever notary.PassRetriever, payload []byte) ([]byte, error) {
err := login(ctx, session, passRetriever, pkcs11.CKU_USER, UserPin)
if err != nil {
return nil, fmt.Errorf("error logging in: %v", err)
}
defer ctx.Logout(session)
// Define the ECDSA Private key template
class := pkcs11.CKO_PRIVATE_KEY
privateKeyTemplate := []*pkcs11.Attribute{
pkcs11.NewAttribute(pkcs11.CKA_CLASS, class),
pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, pkcs11.CKK_ECDSA),
pkcs11.NewAttribute(pkcs11.CKA_ID, pkcs11KeyID),
}
if err := ctx.FindObjectsInit(session, privateKeyTemplate); err != nil {
logrus.Debugf("Failed to init find objects: %s", err.Error())
return nil, err
}
obj, _, err := ctx.FindObjects(session, 1)
if err != nil {
logrus.Debugf("Failed to find objects: %v", err)
return nil, err
}
if err = ctx.FindObjectsFinal(session); err != nil {
logrus.Debugf("Failed to finalize find objects: %s", err.Error())
return nil, err
}
if len(obj) != 1 {
return nil, errors.New("length of objects found not 1")
}
var sig []byte
err = ctx.SignInit(
session, []*pkcs11.Mechanism{pkcs11.NewMechanism(pkcs11.CKM_ECDSA, nil)}, obj[0])
if err != nil {
return nil, err
}
// Get the SHA256 of the payload
digest := sha256.Sum256(payload)
if (yubikeyKeymode & KeymodeTouch) > 0 {
touchToSignUI()
defer touchDoneCallback()
}
// a call to Sign, whether or not Sign fails, will clear the SignInit
sig, err = ctx.Sign(session, digest[:])
if err != nil {
logrus.Debugf("Error while signing: %s", err)
return nil, err
}
if sig == nil {
return nil, errors.New("Failed to create signature")
}
return sig[:], nil
}
|
go
|
func sign(ctx IPKCS11Ctx, session pkcs11.SessionHandle, pkcs11KeyID []byte, passRetriever notary.PassRetriever, payload []byte) ([]byte, error) {
err := login(ctx, session, passRetriever, pkcs11.CKU_USER, UserPin)
if err != nil {
return nil, fmt.Errorf("error logging in: %v", err)
}
defer ctx.Logout(session)
// Define the ECDSA Private key template
class := pkcs11.CKO_PRIVATE_KEY
privateKeyTemplate := []*pkcs11.Attribute{
pkcs11.NewAttribute(pkcs11.CKA_CLASS, class),
pkcs11.NewAttribute(pkcs11.CKA_KEY_TYPE, pkcs11.CKK_ECDSA),
pkcs11.NewAttribute(pkcs11.CKA_ID, pkcs11KeyID),
}
if err := ctx.FindObjectsInit(session, privateKeyTemplate); err != nil {
logrus.Debugf("Failed to init find objects: %s", err.Error())
return nil, err
}
obj, _, err := ctx.FindObjects(session, 1)
if err != nil {
logrus.Debugf("Failed to find objects: %v", err)
return nil, err
}
if err = ctx.FindObjectsFinal(session); err != nil {
logrus.Debugf("Failed to finalize find objects: %s", err.Error())
return nil, err
}
if len(obj) != 1 {
return nil, errors.New("length of objects found not 1")
}
var sig []byte
err = ctx.SignInit(
session, []*pkcs11.Mechanism{pkcs11.NewMechanism(pkcs11.CKM_ECDSA, nil)}, obj[0])
if err != nil {
return nil, err
}
// Get the SHA256 of the payload
digest := sha256.Sum256(payload)
if (yubikeyKeymode & KeymodeTouch) > 0 {
touchToSignUI()
defer touchDoneCallback()
}
// a call to Sign, whether or not Sign fails, will clear the SignInit
sig, err = ctx.Sign(session, digest[:])
if err != nil {
logrus.Debugf("Error while signing: %s", err)
return nil, err
}
if sig == nil {
return nil, errors.New("Failed to create signature")
}
return sig[:], nil
}
|
[
"func",
"sign",
"(",
"ctx",
"IPKCS11Ctx",
",",
"session",
"pkcs11",
".",
"SessionHandle",
",",
"pkcs11KeyID",
"[",
"]",
"byte",
",",
"passRetriever",
"notary",
".",
"PassRetriever",
",",
"payload",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"err",
":=",
"login",
"(",
"ctx",
",",
"session",
",",
"passRetriever",
",",
"pkcs11",
".",
"CKU_USER",
",",
"UserPin",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"ctx",
".",
"Logout",
"(",
"session",
")",
"\n\n",
"// Define the ECDSA Private key template",
"class",
":=",
"pkcs11",
".",
"CKO_PRIVATE_KEY",
"\n",
"privateKeyTemplate",
":=",
"[",
"]",
"*",
"pkcs11",
".",
"Attribute",
"{",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_CLASS",
",",
"class",
")",
",",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_KEY_TYPE",
",",
"pkcs11",
".",
"CKK_ECDSA",
")",
",",
"pkcs11",
".",
"NewAttribute",
"(",
"pkcs11",
".",
"CKA_ID",
",",
"pkcs11KeyID",
")",
",",
"}",
"\n\n",
"if",
"err",
":=",
"ctx",
".",
"FindObjectsInit",
"(",
"session",
",",
"privateKeyTemplate",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"obj",
",",
"_",
",",
"err",
":=",
"ctx",
".",
"FindObjects",
"(",
"session",
",",
"1",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
"=",
"ctx",
".",
"FindObjectsFinal",
"(",
"session",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"len",
"(",
"obj",
")",
"!=",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"var",
"sig",
"[",
"]",
"byte",
"\n",
"err",
"=",
"ctx",
".",
"SignInit",
"(",
"session",
",",
"[",
"]",
"*",
"pkcs11",
".",
"Mechanism",
"{",
"pkcs11",
".",
"NewMechanism",
"(",
"pkcs11",
".",
"CKM_ECDSA",
",",
"nil",
")",
"}",
",",
"obj",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"// Get the SHA256 of the payload",
"digest",
":=",
"sha256",
".",
"Sum256",
"(",
"payload",
")",
"\n\n",
"if",
"(",
"yubikeyKeymode",
"&",
"KeymodeTouch",
")",
">",
"0",
"{",
"touchToSignUI",
"(",
")",
"\n",
"defer",
"touchDoneCallback",
"(",
")",
"\n",
"}",
"\n",
"// a call to Sign, whether or not Sign fails, will clear the SignInit",
"sig",
",",
"err",
"=",
"ctx",
".",
"Sign",
"(",
"session",
",",
"digest",
"[",
":",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"sig",
"==",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"sig",
"[",
":",
"]",
",",
"nil",
"\n",
"}"
] |
// sign returns a signature for a given signature request
|
[
"sign",
"returns",
"a",
"signature",
"for",
"a",
"given",
"signature",
"request"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L349-L406
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
ListKeys
|
func (s *YubiStore) ListKeys() map[string]trustmanager.KeyInfo {
if len(s.keys) > 0 {
return buildKeyMap(s.keys)
}
ctx, session, err := SetupHSMEnv(pkcs11Lib, s.libLoader)
if err != nil {
logrus.Debugf("No yubikey found, using alternative key storage: %s", err.Error())
return nil
}
defer cleanup(ctx, session)
keys, err := yubiListKeys(ctx, session)
if err != nil {
logrus.Debugf("Failed to list key from the yubikey: %s", err.Error())
return nil
}
s.keys = keys
return buildKeyMap(keys)
}
|
go
|
func (s *YubiStore) ListKeys() map[string]trustmanager.KeyInfo {
if len(s.keys) > 0 {
return buildKeyMap(s.keys)
}
ctx, session, err := SetupHSMEnv(pkcs11Lib, s.libLoader)
if err != nil {
logrus.Debugf("No yubikey found, using alternative key storage: %s", err.Error())
return nil
}
defer cleanup(ctx, session)
keys, err := yubiListKeys(ctx, session)
if err != nil {
logrus.Debugf("Failed to list key from the yubikey: %s", err.Error())
return nil
}
s.keys = keys
return buildKeyMap(keys)
}
|
[
"func",
"(",
"s",
"*",
"YubiStore",
")",
"ListKeys",
"(",
")",
"map",
"[",
"string",
"]",
"trustmanager",
".",
"KeyInfo",
"{",
"if",
"len",
"(",
"s",
".",
"keys",
")",
">",
"0",
"{",
"return",
"buildKeyMap",
"(",
"s",
".",
"keys",
")",
"\n",
"}",
"\n",
"ctx",
",",
"session",
",",
"err",
":=",
"SetupHSMEnv",
"(",
"pkcs11Lib",
",",
"s",
".",
"libLoader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"defer",
"cleanup",
"(",
"ctx",
",",
"session",
")",
"\n\n",
"keys",
",",
"err",
":=",
"yubiListKeys",
"(",
"ctx",
",",
"session",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"s",
".",
"keys",
"=",
"keys",
"\n\n",
"return",
"buildKeyMap",
"(",
"keys",
")",
"\n",
"}"
] |
// ListKeys returns a list of keys in the yubikey store
|
[
"ListKeys",
"returns",
"a",
"list",
"of",
"keys",
"in",
"the",
"yubikey",
"store"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L661-L680
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
AddKey
|
func (s *YubiStore) AddKey(keyInfo trustmanager.KeyInfo, privKey data.PrivateKey) error {
added, err := s.addKey(privKey.ID(), keyInfo.Role, privKey)
if err != nil {
return err
}
if added && s.backupStore != nil {
err = s.backupStore.AddKey(keyInfo, privKey)
if err != nil {
defer s.RemoveKey(privKey.ID())
return ErrBackupFailed{err: err.Error()}
}
}
return nil
}
|
go
|
func (s *YubiStore) AddKey(keyInfo trustmanager.KeyInfo, privKey data.PrivateKey) error {
added, err := s.addKey(privKey.ID(), keyInfo.Role, privKey)
if err != nil {
return err
}
if added && s.backupStore != nil {
err = s.backupStore.AddKey(keyInfo, privKey)
if err != nil {
defer s.RemoveKey(privKey.ID())
return ErrBackupFailed{err: err.Error()}
}
}
return nil
}
|
[
"func",
"(",
"s",
"*",
"YubiStore",
")",
"AddKey",
"(",
"keyInfo",
"trustmanager",
".",
"KeyInfo",
",",
"privKey",
"data",
".",
"PrivateKey",
")",
"error",
"{",
"added",
",",
"err",
":=",
"s",
".",
"addKey",
"(",
"privKey",
".",
"ID",
"(",
")",
",",
"keyInfo",
".",
"Role",
",",
"privKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"if",
"added",
"&&",
"s",
".",
"backupStore",
"!=",
"nil",
"{",
"err",
"=",
"s",
".",
"backupStore",
".",
"AddKey",
"(",
"keyInfo",
",",
"privKey",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"defer",
"s",
".",
"RemoveKey",
"(",
"privKey",
".",
"ID",
"(",
")",
")",
"\n",
"return",
"ErrBackupFailed",
"{",
"err",
":",
"err",
".",
"Error",
"(",
")",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// AddKey puts a key inside the Yubikey, as well as writing it to the backup store
|
[
"AddKey",
"puts",
"a",
"key",
"inside",
"the",
"Yubikey",
"as",
"well",
"as",
"writing",
"it",
"to",
"the",
"backup",
"store"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L683-L696
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
addKey
|
func (s *YubiStore) addKey(keyID string, role data.RoleName, privKey data.PrivateKey) (
bool, error) {
// We only allow adding root keys for now
if role != data.CanonicalRootRole {
return false, fmt.Errorf(
"yubikey only supports storing root keys, got %s for key: %s", role, keyID)
}
ctx, session, err := SetupHSMEnv(pkcs11Lib, s.libLoader)
if err != nil {
logrus.Debugf("No yubikey found, using alternative key storage: %s", err.Error())
return false, err
}
defer cleanup(ctx, session)
if k, ok := s.keys[keyID]; ok {
if k.role == role {
// already have the key and it's associated with the correct role
return false, nil
}
}
slot, err := getNextEmptySlot(ctx, session)
if err != nil {
logrus.Debugf("Failed to get an empty yubikey slot: %s", err.Error())
return false, err
}
logrus.Debugf("Attempting to store key using yubikey slot %v", slot)
err = addECDSAKey(
ctx, session, privKey, slot, s.passRetriever, role)
if err == nil {
s.keys[privKey.ID()] = yubiSlot{
role: role,
slotID: slot,
}
return true, nil
}
logrus.Debugf("Failed to add key to yubikey: %v", err)
return false, err
}
|
go
|
func (s *YubiStore) addKey(keyID string, role data.RoleName, privKey data.PrivateKey) (
bool, error) {
// We only allow adding root keys for now
if role != data.CanonicalRootRole {
return false, fmt.Errorf(
"yubikey only supports storing root keys, got %s for key: %s", role, keyID)
}
ctx, session, err := SetupHSMEnv(pkcs11Lib, s.libLoader)
if err != nil {
logrus.Debugf("No yubikey found, using alternative key storage: %s", err.Error())
return false, err
}
defer cleanup(ctx, session)
if k, ok := s.keys[keyID]; ok {
if k.role == role {
// already have the key and it's associated with the correct role
return false, nil
}
}
slot, err := getNextEmptySlot(ctx, session)
if err != nil {
logrus.Debugf("Failed to get an empty yubikey slot: %s", err.Error())
return false, err
}
logrus.Debugf("Attempting to store key using yubikey slot %v", slot)
err = addECDSAKey(
ctx, session, privKey, slot, s.passRetriever, role)
if err == nil {
s.keys[privKey.ID()] = yubiSlot{
role: role,
slotID: slot,
}
return true, nil
}
logrus.Debugf("Failed to add key to yubikey: %v", err)
return false, err
}
|
[
"func",
"(",
"s",
"*",
"YubiStore",
")",
"addKey",
"(",
"keyID",
"string",
",",
"role",
"data",
".",
"RoleName",
",",
"privKey",
"data",
".",
"PrivateKey",
")",
"(",
"bool",
",",
"error",
")",
"{",
"// We only allow adding root keys for now",
"if",
"role",
"!=",
"data",
".",
"CanonicalRootRole",
"{",
"return",
"false",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"role",
",",
"keyID",
")",
"\n",
"}",
"\n\n",
"ctx",
",",
"session",
",",
"err",
":=",
"SetupHSMEnv",
"(",
"pkcs11Lib",
",",
"s",
".",
"libLoader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"defer",
"cleanup",
"(",
"ctx",
",",
"session",
")",
"\n\n",
"if",
"k",
",",
"ok",
":=",
"s",
".",
"keys",
"[",
"keyID",
"]",
";",
"ok",
"{",
"if",
"k",
".",
"role",
"==",
"role",
"{",
"// already have the key and it's associated with the correct role",
"return",
"false",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"slot",
",",
"err",
":=",
"getNextEmptySlot",
"(",
"ctx",
",",
"session",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"false",
",",
"err",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"slot",
")",
"\n\n",
"err",
"=",
"addECDSAKey",
"(",
"ctx",
",",
"session",
",",
"privKey",
",",
"slot",
",",
"s",
".",
"passRetriever",
",",
"role",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"s",
".",
"keys",
"[",
"privKey",
".",
"ID",
"(",
")",
"]",
"=",
"yubiSlot",
"{",
"role",
":",
"role",
",",
"slotID",
":",
"slot",
",",
"}",
"\n",
"return",
"true",
",",
"nil",
"\n",
"}",
"\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n\n",
"return",
"false",
",",
"err",
"\n",
"}"
] |
// Only add if we haven't seen the key already. Return whether the key was
// added.
|
[
"Only",
"add",
"if",
"we",
"haven",
"t",
"seen",
"the",
"key",
"already",
".",
"Return",
"whether",
"the",
"key",
"was",
"added",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L700-L742
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
GetKeyInfo
|
func (s *YubiStore) GetKeyInfo(keyID string) (trustmanager.KeyInfo, error) {
return trustmanager.KeyInfo{}, fmt.Errorf("Not yet implemented")
}
|
go
|
func (s *YubiStore) GetKeyInfo(keyID string) (trustmanager.KeyInfo, error) {
return trustmanager.KeyInfo{}, fmt.Errorf("Not yet implemented")
}
|
[
"func",
"(",
"s",
"*",
"YubiStore",
")",
"GetKeyInfo",
"(",
"keyID",
"string",
")",
"(",
"trustmanager",
".",
"KeyInfo",
",",
"error",
")",
"{",
"return",
"trustmanager",
".",
"KeyInfo",
"{",
"}",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"}"
] |
// GetKeyInfo is not yet implemented
|
[
"GetKeyInfo",
"is",
"not",
"yet",
"implemented"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L804-L806
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
SetupHSMEnv
|
func SetupHSMEnv(libraryPath string, libLoader pkcs11LibLoader) (
IPKCS11Ctx, pkcs11.SessionHandle, error) {
if libraryPath == "" {
return nil, 0, errHSMNotPresent{err: "no library found"}
}
p := libLoader(libraryPath)
if p == nil {
return nil, 0, fmt.Errorf("failed to load library %s", libraryPath)
}
if err := p.Initialize(); err != nil {
defer finalizeAndDestroy(p)
return nil, 0, fmt.Errorf("found library %s, but initialize error %s", libraryPath, err.Error())
}
slots, err := p.GetSlotList(true)
if err != nil {
defer finalizeAndDestroy(p)
return nil, 0, fmt.Errorf(
"loaded library %s, but failed to list HSM slots %s", libraryPath, err)
}
// Check to see if we got any slots from the HSM.
if len(slots) < 1 {
defer finalizeAndDestroy(p)
return nil, 0, fmt.Errorf(
"loaded library %s, but no HSM slots found", libraryPath)
}
// CKF_SERIAL_SESSION: TRUE if cryptographic functions are performed in serial with the application; FALSE if the functions may be performed in parallel with the application.
// CKF_RW_SESSION: TRUE if the session is read/write; FALSE if the session is read-only
session, err := p.OpenSession(slots[0], pkcs11.CKF_SERIAL_SESSION|pkcs11.CKF_RW_SESSION)
if err != nil {
defer cleanup(p, session)
return nil, 0, fmt.Errorf(
"loaded library %s, but failed to start session with HSM %s",
libraryPath, err)
}
logrus.Debugf("Initialized PKCS11 library %s and started HSM session", libraryPath)
return p, session, nil
}
|
go
|
func SetupHSMEnv(libraryPath string, libLoader pkcs11LibLoader) (
IPKCS11Ctx, pkcs11.SessionHandle, error) {
if libraryPath == "" {
return nil, 0, errHSMNotPresent{err: "no library found"}
}
p := libLoader(libraryPath)
if p == nil {
return nil, 0, fmt.Errorf("failed to load library %s", libraryPath)
}
if err := p.Initialize(); err != nil {
defer finalizeAndDestroy(p)
return nil, 0, fmt.Errorf("found library %s, but initialize error %s", libraryPath, err.Error())
}
slots, err := p.GetSlotList(true)
if err != nil {
defer finalizeAndDestroy(p)
return nil, 0, fmt.Errorf(
"loaded library %s, but failed to list HSM slots %s", libraryPath, err)
}
// Check to see if we got any slots from the HSM.
if len(slots) < 1 {
defer finalizeAndDestroy(p)
return nil, 0, fmt.Errorf(
"loaded library %s, but no HSM slots found", libraryPath)
}
// CKF_SERIAL_SESSION: TRUE if cryptographic functions are performed in serial with the application; FALSE if the functions may be performed in parallel with the application.
// CKF_RW_SESSION: TRUE if the session is read/write; FALSE if the session is read-only
session, err := p.OpenSession(slots[0], pkcs11.CKF_SERIAL_SESSION|pkcs11.CKF_RW_SESSION)
if err != nil {
defer cleanup(p, session)
return nil, 0, fmt.Errorf(
"loaded library %s, but failed to start session with HSM %s",
libraryPath, err)
}
logrus.Debugf("Initialized PKCS11 library %s and started HSM session", libraryPath)
return p, session, nil
}
|
[
"func",
"SetupHSMEnv",
"(",
"libraryPath",
"string",
",",
"libLoader",
"pkcs11LibLoader",
")",
"(",
"IPKCS11Ctx",
",",
"pkcs11",
".",
"SessionHandle",
",",
"error",
")",
"{",
"if",
"libraryPath",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"0",
",",
"errHSMNotPresent",
"{",
"err",
":",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"p",
":=",
"libLoader",
"(",
"libraryPath",
")",
"\n\n",
"if",
"p",
"==",
"nil",
"{",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"libraryPath",
")",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"p",
".",
"Initialize",
"(",
")",
";",
"err",
"!=",
"nil",
"{",
"defer",
"finalizeAndDestroy",
"(",
"p",
")",
"\n",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"libraryPath",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"}",
"\n\n",
"slots",
",",
"err",
":=",
"p",
".",
"GetSlotList",
"(",
"true",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"defer",
"finalizeAndDestroy",
"(",
"p",
")",
"\n",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"libraryPath",
",",
"err",
")",
"\n",
"}",
"\n",
"// Check to see if we got any slots from the HSM.",
"if",
"len",
"(",
"slots",
")",
"<",
"1",
"{",
"defer",
"finalizeAndDestroy",
"(",
"p",
")",
"\n",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"libraryPath",
")",
"\n",
"}",
"\n\n",
"// CKF_SERIAL_SESSION: TRUE if cryptographic functions are performed in serial with the application; FALSE if the functions may be performed in parallel with the application.",
"// CKF_RW_SESSION: TRUE if the session is read/write; FALSE if the session is read-only",
"session",
",",
"err",
":=",
"p",
".",
"OpenSession",
"(",
"slots",
"[",
"0",
"]",
",",
"pkcs11",
".",
"CKF_SERIAL_SESSION",
"|",
"pkcs11",
".",
"CKF_RW_SESSION",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"defer",
"cleanup",
"(",
"p",
",",
"session",
")",
"\n",
"return",
"nil",
",",
"0",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"libraryPath",
",",
"err",
")",
"\n",
"}",
"\n\n",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"libraryPath",
")",
"\n",
"return",
"p",
",",
"session",
",",
"nil",
"\n",
"}"
] |
// SetupHSMEnv is a method that depends on the existences
|
[
"SetupHSMEnv",
"is",
"a",
"method",
"that",
"depends",
"on",
"the",
"existences"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L825-L867
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/yubikeystore.go
|
IsAccessible
|
func IsAccessible() bool {
if pkcs11Lib == "" {
return false
}
ctx, session, err := SetupHSMEnv(pkcs11Lib, defaultLoader)
if err != nil {
return false
}
defer cleanup(ctx, session)
return true
}
|
go
|
func IsAccessible() bool {
if pkcs11Lib == "" {
return false
}
ctx, session, err := SetupHSMEnv(pkcs11Lib, defaultLoader)
if err != nil {
return false
}
defer cleanup(ctx, session)
return true
}
|
[
"func",
"IsAccessible",
"(",
")",
"bool",
"{",
"if",
"pkcs11Lib",
"==",
"\"",
"\"",
"{",
"return",
"false",
"\n",
"}",
"\n",
"ctx",
",",
"session",
",",
"err",
":=",
"SetupHSMEnv",
"(",
"pkcs11Lib",
",",
"defaultLoader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"false",
"\n",
"}",
"\n",
"defer",
"cleanup",
"(",
"ctx",
",",
"session",
")",
"\n",
"return",
"true",
"\n",
"}"
] |
// IsAccessible returns true if a Yubikey can be accessed
|
[
"IsAccessible",
"returns",
"true",
"if",
"a",
"Yubikey",
"can",
"be",
"accessed"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/yubikeystore.go#L870-L880
|
train
|
theupdateframework/notary
|
tuf/signed/verifiers.go
|
Verify
|
func (v Ed25519Verifier) Verify(key data.PublicKey, sig []byte, msg []byte) error {
if key.Algorithm() != data.ED25519Key {
return ErrInvalidKeyType{}
}
sigBytes := make([]byte, ed25519.SignatureSize)
if len(sig) != ed25519.SignatureSize {
logrus.Debugf("signature length is incorrect, must be %d, was %d.", ed25519.SignatureSize, len(sig))
return ErrInvalid
}
copy(sigBytes, sig)
keyBytes := make([]byte, ed25519.PublicKeySize)
pub := key.Public()
if len(pub) != ed25519.PublicKeySize {
logrus.Errorf("public key is incorrect size, must be %d, was %d.", ed25519.PublicKeySize, len(pub))
return ErrInvalidKeyLength{msg: fmt.Sprintf("ed25519 public key must be %d bytes.", ed25519.PublicKeySize)}
}
n := copy(keyBytes, key.Public())
if n < ed25519.PublicKeySize {
logrus.Errorf("failed to copy the key, must have %d bytes, copied %d bytes.", ed25519.PublicKeySize, n)
return ErrInvalid
}
if !ed25519.Verify(ed25519.PublicKey(keyBytes), msg, sigBytes) {
logrus.Debugf("failed ed25519 verification")
return ErrInvalid
}
return nil
}
|
go
|
func (v Ed25519Verifier) Verify(key data.PublicKey, sig []byte, msg []byte) error {
if key.Algorithm() != data.ED25519Key {
return ErrInvalidKeyType{}
}
sigBytes := make([]byte, ed25519.SignatureSize)
if len(sig) != ed25519.SignatureSize {
logrus.Debugf("signature length is incorrect, must be %d, was %d.", ed25519.SignatureSize, len(sig))
return ErrInvalid
}
copy(sigBytes, sig)
keyBytes := make([]byte, ed25519.PublicKeySize)
pub := key.Public()
if len(pub) != ed25519.PublicKeySize {
logrus.Errorf("public key is incorrect size, must be %d, was %d.", ed25519.PublicKeySize, len(pub))
return ErrInvalidKeyLength{msg: fmt.Sprintf("ed25519 public key must be %d bytes.", ed25519.PublicKeySize)}
}
n := copy(keyBytes, key.Public())
if n < ed25519.PublicKeySize {
logrus.Errorf("failed to copy the key, must have %d bytes, copied %d bytes.", ed25519.PublicKeySize, n)
return ErrInvalid
}
if !ed25519.Verify(ed25519.PublicKey(keyBytes), msg, sigBytes) {
logrus.Debugf("failed ed25519 verification")
return ErrInvalid
}
return nil
}
|
[
"func",
"(",
"v",
"Ed25519Verifier",
")",
"Verify",
"(",
"key",
"data",
".",
"PublicKey",
",",
"sig",
"[",
"]",
"byte",
",",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"if",
"key",
".",
"Algorithm",
"(",
")",
"!=",
"data",
".",
"ED25519Key",
"{",
"return",
"ErrInvalidKeyType",
"{",
"}",
"\n",
"}",
"\n",
"sigBytes",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"ed25519",
".",
"SignatureSize",
")",
"\n",
"if",
"len",
"(",
"sig",
")",
"!=",
"ed25519",
".",
"SignatureSize",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"ed25519",
".",
"SignatureSize",
",",
"len",
"(",
"sig",
")",
")",
"\n",
"return",
"ErrInvalid",
"\n",
"}",
"\n",
"copy",
"(",
"sigBytes",
",",
"sig",
")",
"\n\n",
"keyBytes",
":=",
"make",
"(",
"[",
"]",
"byte",
",",
"ed25519",
".",
"PublicKeySize",
")",
"\n",
"pub",
":=",
"key",
".",
"Public",
"(",
")",
"\n",
"if",
"len",
"(",
"pub",
")",
"!=",
"ed25519",
".",
"PublicKeySize",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ed25519",
".",
"PublicKeySize",
",",
"len",
"(",
"pub",
")",
")",
"\n",
"return",
"ErrInvalidKeyLength",
"{",
"msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"ed25519",
".",
"PublicKeySize",
")",
"}",
"\n",
"}",
"\n",
"n",
":=",
"copy",
"(",
"keyBytes",
",",
"key",
".",
"Public",
"(",
")",
")",
"\n",
"if",
"n",
"<",
"ed25519",
".",
"PublicKeySize",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"ed25519",
".",
"PublicKeySize",
",",
"n",
")",
"\n",
"return",
"ErrInvalid",
"\n",
"}",
"\n\n",
"if",
"!",
"ed25519",
".",
"Verify",
"(",
"ed25519",
".",
"PublicKey",
"(",
"keyBytes",
")",
",",
"msg",
",",
"sigBytes",
")",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"ErrInvalid",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Verify checks that an ed25519 signature is valid
|
[
"Verify",
"checks",
"that",
"an",
"ed25519",
"signature",
"is",
"valid"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verifiers.go#L38-L66
|
train
|
theupdateframework/notary
|
tuf/signed/verifiers.go
|
Verify
|
func (v RSAPKCS1v15Verifier) Verify(key data.PublicKey, sig []byte, msg []byte) error {
// will return err if keytype is not a recognized RSA type
pubKey, err := getRSAPubKey(key)
if err != nil {
return err
}
digest := sha256.Sum256(msg)
rsaPub, ok := pubKey.(*rsa.PublicKey)
if !ok {
logrus.Debugf("value was not an RSA public key")
return ErrInvalid
}
if rsaPub.N.BitLen() < minRSAKeySizeBit {
logrus.Debugf("RSA keys less than 2048 bits are not acceptable, provided key has length %d.", rsaPub.N.BitLen())
return ErrInvalidKeyLength{msg: fmt.Sprintf("RSA key must be at least %d bits.", minRSAKeySizeBit)}
}
if len(sig) < minRSAKeySizeByte {
logrus.Debugf("RSA keys less than 2048 bits are not acceptable, provided signature has length %d.", len(sig))
return ErrInvalid
}
if err = rsa.VerifyPKCS1v15(rsaPub, crypto.SHA256, digest[:], sig); err != nil {
logrus.Errorf("Failed verification: %s", err.Error())
return ErrInvalid
}
return nil
}
|
go
|
func (v RSAPKCS1v15Verifier) Verify(key data.PublicKey, sig []byte, msg []byte) error {
// will return err if keytype is not a recognized RSA type
pubKey, err := getRSAPubKey(key)
if err != nil {
return err
}
digest := sha256.Sum256(msg)
rsaPub, ok := pubKey.(*rsa.PublicKey)
if !ok {
logrus.Debugf("value was not an RSA public key")
return ErrInvalid
}
if rsaPub.N.BitLen() < minRSAKeySizeBit {
logrus.Debugf("RSA keys less than 2048 bits are not acceptable, provided key has length %d.", rsaPub.N.BitLen())
return ErrInvalidKeyLength{msg: fmt.Sprintf("RSA key must be at least %d bits.", minRSAKeySizeBit)}
}
if len(sig) < minRSAKeySizeByte {
logrus.Debugf("RSA keys less than 2048 bits are not acceptable, provided signature has length %d.", len(sig))
return ErrInvalid
}
if err = rsa.VerifyPKCS1v15(rsaPub, crypto.SHA256, digest[:], sig); err != nil {
logrus.Errorf("Failed verification: %s", err.Error())
return ErrInvalid
}
return nil
}
|
[
"func",
"(",
"v",
"RSAPKCS1v15Verifier",
")",
"Verify",
"(",
"key",
"data",
".",
"PublicKey",
",",
"sig",
"[",
"]",
"byte",
",",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"// will return err if keytype is not a recognized RSA type",
"pubKey",
",",
"err",
":=",
"getRSAPubKey",
"(",
"key",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"digest",
":=",
"sha256",
".",
"Sum256",
"(",
"msg",
")",
"\n\n",
"rsaPub",
",",
"ok",
":=",
"pubKey",
".",
"(",
"*",
"rsa",
".",
"PublicKey",
")",
"\n",
"if",
"!",
"ok",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"ErrInvalid",
"\n",
"}",
"\n\n",
"if",
"rsaPub",
".",
"N",
".",
"BitLen",
"(",
")",
"<",
"minRSAKeySizeBit",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"rsaPub",
".",
"N",
".",
"BitLen",
"(",
")",
")",
"\n",
"return",
"ErrInvalidKeyLength",
"{",
"msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"minRSAKeySizeBit",
")",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"sig",
")",
"<",
"minRSAKeySizeByte",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"len",
"(",
"sig",
")",
")",
"\n",
"return",
"ErrInvalid",
"\n",
"}",
"\n\n",
"if",
"err",
"=",
"rsa",
".",
"VerifyPKCS1v15",
"(",
"rsaPub",
",",
"crypto",
".",
"SHA256",
",",
"digest",
"[",
":",
"]",
",",
"sig",
")",
";",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
".",
"Error",
"(",
")",
")",
"\n",
"return",
"ErrInvalid",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] |
// Verify does the actual verification
|
[
"Verify",
"does",
"the",
"actual",
"verification"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verifiers.go#L146-L175
|
train
|
theupdateframework/notary
|
tuf/signed/verifiers.go
|
Verify
|
func (v RSAPyCryptoVerifier) Verify(key data.PublicKey, sig []byte, msg []byte) error {
digest := sha256.Sum256(msg)
if key.Algorithm() != data.RSAKey {
return ErrInvalidKeyType{}
}
k, _ := pem.Decode([]byte(key.Public()))
if k == nil {
logrus.Debugf("failed to decode PEM-encoded x509 certificate")
return ErrInvalid
}
pub, err := x509.ParsePKIXPublicKey(k.Bytes)
if err != nil {
logrus.Debugf("failed to parse public key: %s\n", err)
return ErrInvalid
}
return verifyPSS(pub, digest[:], sig)
}
|
go
|
func (v RSAPyCryptoVerifier) Verify(key data.PublicKey, sig []byte, msg []byte) error {
digest := sha256.Sum256(msg)
if key.Algorithm() != data.RSAKey {
return ErrInvalidKeyType{}
}
k, _ := pem.Decode([]byte(key.Public()))
if k == nil {
logrus.Debugf("failed to decode PEM-encoded x509 certificate")
return ErrInvalid
}
pub, err := x509.ParsePKIXPublicKey(k.Bytes)
if err != nil {
logrus.Debugf("failed to parse public key: %s\n", err)
return ErrInvalid
}
return verifyPSS(pub, digest[:], sig)
}
|
[
"func",
"(",
"v",
"RSAPyCryptoVerifier",
")",
"Verify",
"(",
"key",
"data",
".",
"PublicKey",
",",
"sig",
"[",
"]",
"byte",
",",
"msg",
"[",
"]",
"byte",
")",
"error",
"{",
"digest",
":=",
"sha256",
".",
"Sum256",
"(",
"msg",
")",
"\n",
"if",
"key",
".",
"Algorithm",
"(",
")",
"!=",
"data",
".",
"RSAKey",
"{",
"return",
"ErrInvalidKeyType",
"{",
"}",
"\n",
"}",
"\n\n",
"k",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"[",
"]",
"byte",
"(",
"key",
".",
"Public",
"(",
")",
")",
")",
"\n",
"if",
"k",
"==",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"ErrInvalid",
"\n",
"}",
"\n\n",
"pub",
",",
"err",
":=",
"x509",
".",
"ParsePKIXPublicKey",
"(",
"k",
".",
"Bytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Debugf",
"(",
"\"",
"\\n",
"\"",
",",
"err",
")",
"\n",
"return",
"ErrInvalid",
"\n",
"}",
"\n\n",
"return",
"verifyPSS",
"(",
"pub",
",",
"digest",
"[",
":",
"]",
",",
"sig",
")",
"\n",
"}"
] |
// Verify does the actual check.
// N.B. We have not been able to make this work in a way that is compatible
// with PyCrypto.
|
[
"Verify",
"does",
"the",
"actual",
"check",
".",
"N",
".",
"B",
".",
"We",
"have",
"not",
"been",
"able",
"to",
"make",
"this",
"work",
"in",
"a",
"way",
"that",
"is",
"compatible",
"with",
"PyCrypto",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/signed/verifiers.go#L183-L202
|
train
|
theupdateframework/notary
|
signer/keydbstore/keydbstore.go
|
generatePrivateKey
|
func generatePrivateKey(algorithm string) (data.PrivateKey, error) {
var privKey data.PrivateKey
var err error
switch algorithm {
case data.ECDSAKey:
privKey, err = utils.GenerateECDSAKey(rand.Reader)
if err != nil {
return nil, fmt.Errorf("failed to generate EC key: %v", err)
}
case data.ED25519Key:
privKey, err = utils.GenerateED25519Key(rand.Reader)
if err != nil {
return nil, fmt.Errorf("failed to generate ED25519 key: %v", err)
}
default:
return nil, fmt.Errorf("private key type not supported for key generation: %s", algorithm)
}
return privKey, nil
}
|
go
|
func generatePrivateKey(algorithm string) (data.PrivateKey, error) {
var privKey data.PrivateKey
var err error
switch algorithm {
case data.ECDSAKey:
privKey, err = utils.GenerateECDSAKey(rand.Reader)
if err != nil {
return nil, fmt.Errorf("failed to generate EC key: %v", err)
}
case data.ED25519Key:
privKey, err = utils.GenerateED25519Key(rand.Reader)
if err != nil {
return nil, fmt.Errorf("failed to generate ED25519 key: %v", err)
}
default:
return nil, fmt.Errorf("private key type not supported for key generation: %s", algorithm)
}
return privKey, nil
}
|
[
"func",
"generatePrivateKey",
"(",
"algorithm",
"string",
")",
"(",
"data",
".",
"PrivateKey",
",",
"error",
")",
"{",
"var",
"privKey",
"data",
".",
"PrivateKey",
"\n",
"var",
"err",
"error",
"\n",
"switch",
"algorithm",
"{",
"case",
"data",
".",
"ECDSAKey",
":",
"privKey",
",",
"err",
"=",
"utils",
".",
"GenerateECDSAKey",
"(",
"rand",
".",
"Reader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"case",
"data",
".",
"ED25519Key",
":",
"privKey",
",",
"err",
"=",
"utils",
".",
"GenerateED25519Key",
"(",
"rand",
".",
"Reader",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"default",
":",
"return",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"algorithm",
")",
"\n",
"}",
"\n",
"return",
"privKey",
",",
"nil",
"\n",
"}"
] |
// helper function to generate private keys for the signer databases - does not implement RSA since that is not
// supported by the signer
|
[
"helper",
"function",
"to",
"generate",
"private",
"keys",
"for",
"the",
"signer",
"databases",
"-",
"does",
"not",
"implement",
"RSA",
"since",
"that",
"is",
"not",
"supported",
"by",
"the",
"signer"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/signer/keydbstore/keydbstore.go#L33-L51
|
train
|
theupdateframework/notary
|
tuf/data/serializer.go
|
Unmarshal
|
func (c canonicalJSON) Unmarshal(from []byte, to interface{}) error {
return json.Unmarshal(from, to)
}
|
go
|
func (c canonicalJSON) Unmarshal(from []byte, to interface{}) error {
return json.Unmarshal(from, to)
}
|
[
"func",
"(",
"c",
"canonicalJSON",
")",
"Unmarshal",
"(",
"from",
"[",
"]",
"byte",
",",
"to",
"interface",
"{",
"}",
")",
"error",
"{",
"return",
"json",
".",
"Unmarshal",
"(",
"from",
",",
"to",
")",
"\n",
"}"
] |
// Unmarshal unmarshals some JSON bytes
|
[
"Unmarshal",
"unmarshals",
"some",
"JSON",
"bytes"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/serializer.go#L27-L29
|
train
|
theupdateframework/notary
|
tuf/data/timestamp.go
|
IsValidTimestampStructure
|
func IsValidTimestampStructure(t Timestamp) error {
expectedType := TUFTypes[CanonicalTimestampRole]
if t.Type != expectedType {
return ErrInvalidMetadata{
role: CanonicalTimestampRole, msg: fmt.Sprintf("expected type %s, not %s", expectedType, t.Type)}
}
if t.Version < 1 {
return ErrInvalidMetadata{
role: CanonicalTimestampRole, msg: "version cannot be less than one"}
}
// Meta is a map of FileMeta, so if the role isn't in the map it returns
// an empty FileMeta, which has an empty map, and you can check on keys
// from an empty map.
//
// For now sha256 is required and sha512 is not.
if _, ok := t.Meta[CanonicalSnapshotRole.String()].Hashes[notary.SHA256]; !ok {
return ErrInvalidMetadata{
role: CanonicalTimestampRole, msg: "missing snapshot sha256 checksum information"}
}
if err := CheckValidHashStructures(t.Meta[CanonicalSnapshotRole.String()].Hashes); err != nil {
return ErrInvalidMetadata{
role: CanonicalTimestampRole, msg: fmt.Sprintf("invalid snapshot checksum information, %v", err)}
}
return nil
}
|
go
|
func IsValidTimestampStructure(t Timestamp) error {
expectedType := TUFTypes[CanonicalTimestampRole]
if t.Type != expectedType {
return ErrInvalidMetadata{
role: CanonicalTimestampRole, msg: fmt.Sprintf("expected type %s, not %s", expectedType, t.Type)}
}
if t.Version < 1 {
return ErrInvalidMetadata{
role: CanonicalTimestampRole, msg: "version cannot be less than one"}
}
// Meta is a map of FileMeta, so if the role isn't in the map it returns
// an empty FileMeta, which has an empty map, and you can check on keys
// from an empty map.
//
// For now sha256 is required and sha512 is not.
if _, ok := t.Meta[CanonicalSnapshotRole.String()].Hashes[notary.SHA256]; !ok {
return ErrInvalidMetadata{
role: CanonicalTimestampRole, msg: "missing snapshot sha256 checksum information"}
}
if err := CheckValidHashStructures(t.Meta[CanonicalSnapshotRole.String()].Hashes); err != nil {
return ErrInvalidMetadata{
role: CanonicalTimestampRole, msg: fmt.Sprintf("invalid snapshot checksum information, %v", err)}
}
return nil
}
|
[
"func",
"IsValidTimestampStructure",
"(",
"t",
"Timestamp",
")",
"error",
"{",
"expectedType",
":=",
"TUFTypes",
"[",
"CanonicalTimestampRole",
"]",
"\n",
"if",
"t",
".",
"Type",
"!=",
"expectedType",
"{",
"return",
"ErrInvalidMetadata",
"{",
"role",
":",
"CanonicalTimestampRole",
",",
"msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"expectedType",
",",
"t",
".",
"Type",
")",
"}",
"\n",
"}",
"\n\n",
"if",
"t",
".",
"Version",
"<",
"1",
"{",
"return",
"ErrInvalidMetadata",
"{",
"role",
":",
"CanonicalTimestampRole",
",",
"msg",
":",
"\"",
"\"",
"}",
"\n",
"}",
"\n\n",
"// Meta is a map of FileMeta, so if the role isn't in the map it returns",
"// an empty FileMeta, which has an empty map, and you can check on keys",
"// from an empty map.",
"//",
"// For now sha256 is required and sha512 is not.",
"if",
"_",
",",
"ok",
":=",
"t",
".",
"Meta",
"[",
"CanonicalSnapshotRole",
".",
"String",
"(",
")",
"]",
".",
"Hashes",
"[",
"notary",
".",
"SHA256",
"]",
";",
"!",
"ok",
"{",
"return",
"ErrInvalidMetadata",
"{",
"role",
":",
"CanonicalTimestampRole",
",",
"msg",
":",
"\"",
"\"",
"}",
"\n",
"}",
"\n",
"if",
"err",
":=",
"CheckValidHashStructures",
"(",
"t",
".",
"Meta",
"[",
"CanonicalSnapshotRole",
".",
"String",
"(",
")",
"]",
".",
"Hashes",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"ErrInvalidMetadata",
"{",
"role",
":",
"CanonicalTimestampRole",
",",
"msg",
":",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
")",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] |
// IsValidTimestampStructure returns an error, or nil, depending on whether the content of the struct
// is valid for timestamp metadata. This does not check signatures or expiry, just that
// the metadata content is valid.
|
[
"IsValidTimestampStructure",
"returns",
"an",
"error",
"or",
"nil",
"depending",
"on",
"whether",
"the",
"content",
"of",
"the",
"struct",
"is",
"valid",
"for",
"timestamp",
"metadata",
".",
"This",
"does",
"not",
"check",
"signatures",
"or",
"expiry",
"just",
"that",
"the",
"metadata",
"content",
"is",
"valid",
"."
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L27-L54
|
train
|
theupdateframework/notary
|
tuf/data/timestamp.go
|
NewTimestamp
|
func NewTimestamp(snapshot *Signed) (*SignedTimestamp, error) {
snapshotJSON, err := json.Marshal(snapshot)
if err != nil {
return nil, err
}
snapshotMeta, err := NewFileMeta(bytes.NewReader(snapshotJSON), NotaryDefaultHashes...)
if err != nil {
return nil, err
}
return &SignedTimestamp{
Signatures: make([]Signature, 0),
Signed: Timestamp{
SignedCommon: SignedCommon{
Type: TUFTypes[CanonicalTimestampRole],
Version: 0,
Expires: DefaultExpires(CanonicalTimestampRole),
},
Meta: Files{
CanonicalSnapshotRole.String(): snapshotMeta,
},
},
}, nil
}
|
go
|
func NewTimestamp(snapshot *Signed) (*SignedTimestamp, error) {
snapshotJSON, err := json.Marshal(snapshot)
if err != nil {
return nil, err
}
snapshotMeta, err := NewFileMeta(bytes.NewReader(snapshotJSON), NotaryDefaultHashes...)
if err != nil {
return nil, err
}
return &SignedTimestamp{
Signatures: make([]Signature, 0),
Signed: Timestamp{
SignedCommon: SignedCommon{
Type: TUFTypes[CanonicalTimestampRole],
Version: 0,
Expires: DefaultExpires(CanonicalTimestampRole),
},
Meta: Files{
CanonicalSnapshotRole.String(): snapshotMeta,
},
},
}, nil
}
|
[
"func",
"NewTimestamp",
"(",
"snapshot",
"*",
"Signed",
")",
"(",
"*",
"SignedTimestamp",
",",
"error",
")",
"{",
"snapshotJSON",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"snapshot",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"snapshotMeta",
",",
"err",
":=",
"NewFileMeta",
"(",
"bytes",
".",
"NewReader",
"(",
"snapshotJSON",
")",
",",
"NotaryDefaultHashes",
"...",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"&",
"SignedTimestamp",
"{",
"Signatures",
":",
"make",
"(",
"[",
"]",
"Signature",
",",
"0",
")",
",",
"Signed",
":",
"Timestamp",
"{",
"SignedCommon",
":",
"SignedCommon",
"{",
"Type",
":",
"TUFTypes",
"[",
"CanonicalTimestampRole",
"]",
",",
"Version",
":",
"0",
",",
"Expires",
":",
"DefaultExpires",
"(",
"CanonicalTimestampRole",
")",
",",
"}",
",",
"Meta",
":",
"Files",
"{",
"CanonicalSnapshotRole",
".",
"String",
"(",
")",
":",
"snapshotMeta",
",",
"}",
",",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// NewTimestamp initializes a timestamp with an existing snapshot
|
[
"NewTimestamp",
"initializes",
"a",
"timestamp",
"with",
"an",
"existing",
"snapshot"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L57-L79
|
train
|
theupdateframework/notary
|
tuf/data/timestamp.go
|
ToSigned
|
func (ts *SignedTimestamp) ToSigned() (*Signed, error) {
s, err := defaultSerializer.MarshalCanonical(ts.Signed)
if err != nil {
return nil, err
}
signed := json.RawMessage{}
err = signed.UnmarshalJSON(s)
if err != nil {
return nil, err
}
sigs := make([]Signature, len(ts.Signatures))
copy(sigs, ts.Signatures)
return &Signed{
Signatures: sigs,
Signed: &signed,
}, nil
}
|
go
|
func (ts *SignedTimestamp) ToSigned() (*Signed, error) {
s, err := defaultSerializer.MarshalCanonical(ts.Signed)
if err != nil {
return nil, err
}
signed := json.RawMessage{}
err = signed.UnmarshalJSON(s)
if err != nil {
return nil, err
}
sigs := make([]Signature, len(ts.Signatures))
copy(sigs, ts.Signatures)
return &Signed{
Signatures: sigs,
Signed: &signed,
}, nil
}
|
[
"func",
"(",
"ts",
"*",
"SignedTimestamp",
")",
"ToSigned",
"(",
")",
"(",
"*",
"Signed",
",",
"error",
")",
"{",
"s",
",",
"err",
":=",
"defaultSerializer",
".",
"MarshalCanonical",
"(",
"ts",
".",
"Signed",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"signed",
":=",
"json",
".",
"RawMessage",
"{",
"}",
"\n",
"err",
"=",
"signed",
".",
"UnmarshalJSON",
"(",
"s",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"sigs",
":=",
"make",
"(",
"[",
"]",
"Signature",
",",
"len",
"(",
"ts",
".",
"Signatures",
")",
")",
"\n",
"copy",
"(",
"sigs",
",",
"ts",
".",
"Signatures",
")",
"\n",
"return",
"&",
"Signed",
"{",
"Signatures",
":",
"sigs",
",",
"Signed",
":",
"&",
"signed",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// ToSigned partially serializes a SignedTimestamp such that it can
// be signed
|
[
"ToSigned",
"partially",
"serializes",
"a",
"SignedTimestamp",
"such",
"that",
"it",
"can",
"be",
"signed"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L83-L99
|
train
|
theupdateframework/notary
|
tuf/data/timestamp.go
|
GetSnapshot
|
func (ts *SignedTimestamp) GetSnapshot() (*FileMeta, error) {
snapshotExpected, ok := ts.Signed.Meta[CanonicalSnapshotRole.String()]
if !ok {
return nil, ErrMissingMeta{Role: CanonicalSnapshotRole.String()}
}
return &snapshotExpected, nil
}
|
go
|
func (ts *SignedTimestamp) GetSnapshot() (*FileMeta, error) {
snapshotExpected, ok := ts.Signed.Meta[CanonicalSnapshotRole.String()]
if !ok {
return nil, ErrMissingMeta{Role: CanonicalSnapshotRole.String()}
}
return &snapshotExpected, nil
}
|
[
"func",
"(",
"ts",
"*",
"SignedTimestamp",
")",
"GetSnapshot",
"(",
")",
"(",
"*",
"FileMeta",
",",
"error",
")",
"{",
"snapshotExpected",
",",
"ok",
":=",
"ts",
".",
"Signed",
".",
"Meta",
"[",
"CanonicalSnapshotRole",
".",
"String",
"(",
")",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrMissingMeta",
"{",
"Role",
":",
"CanonicalSnapshotRole",
".",
"String",
"(",
")",
"}",
"\n",
"}",
"\n",
"return",
"&",
"snapshotExpected",
",",
"nil",
"\n",
"}"
] |
// GetSnapshot gets the expected snapshot metadata hashes in the timestamp metadata,
// or nil if it doesn't exist
|
[
"GetSnapshot",
"gets",
"the",
"expected",
"snapshot",
"metadata",
"hashes",
"in",
"the",
"timestamp",
"metadata",
"or",
"nil",
"if",
"it",
"doesn",
"t",
"exist"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L103-L109
|
train
|
theupdateframework/notary
|
tuf/data/timestamp.go
|
MarshalJSON
|
func (ts *SignedTimestamp) MarshalJSON() ([]byte, error) {
signed, err := ts.ToSigned()
if err != nil {
return nil, err
}
return defaultSerializer.Marshal(signed)
}
|
go
|
func (ts *SignedTimestamp) MarshalJSON() ([]byte, error) {
signed, err := ts.ToSigned()
if err != nil {
return nil, err
}
return defaultSerializer.Marshal(signed)
}
|
[
"func",
"(",
"ts",
"*",
"SignedTimestamp",
")",
"MarshalJSON",
"(",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"signed",
",",
"err",
":=",
"ts",
".",
"ToSigned",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"defaultSerializer",
".",
"Marshal",
"(",
"signed",
")",
"\n",
"}"
] |
// MarshalJSON returns the serialized form of SignedTimestamp as bytes
|
[
"MarshalJSON",
"returns",
"the",
"serialized",
"form",
"of",
"SignedTimestamp",
"as",
"bytes"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L112-L118
|
train
|
theupdateframework/notary
|
tuf/data/timestamp.go
|
TimestampFromSigned
|
func TimestampFromSigned(s *Signed) (*SignedTimestamp, error) {
ts := Timestamp{}
if err := defaultSerializer.Unmarshal(*s.Signed, &ts); err != nil {
return nil, err
}
if err := IsValidTimestampStructure(ts); err != nil {
return nil, err
}
sigs := make([]Signature, len(s.Signatures))
copy(sigs, s.Signatures)
return &SignedTimestamp{
Signatures: sigs,
Signed: ts,
}, nil
}
|
go
|
func TimestampFromSigned(s *Signed) (*SignedTimestamp, error) {
ts := Timestamp{}
if err := defaultSerializer.Unmarshal(*s.Signed, &ts); err != nil {
return nil, err
}
if err := IsValidTimestampStructure(ts); err != nil {
return nil, err
}
sigs := make([]Signature, len(s.Signatures))
copy(sigs, s.Signatures)
return &SignedTimestamp{
Signatures: sigs,
Signed: ts,
}, nil
}
|
[
"func",
"TimestampFromSigned",
"(",
"s",
"*",
"Signed",
")",
"(",
"*",
"SignedTimestamp",
",",
"error",
")",
"{",
"ts",
":=",
"Timestamp",
"{",
"}",
"\n",
"if",
"err",
":=",
"defaultSerializer",
".",
"Unmarshal",
"(",
"*",
"s",
".",
"Signed",
",",
"&",
"ts",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"if",
"err",
":=",
"IsValidTimestampStructure",
"(",
"ts",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"sigs",
":=",
"make",
"(",
"[",
"]",
"Signature",
",",
"len",
"(",
"s",
".",
"Signatures",
")",
")",
"\n",
"copy",
"(",
"sigs",
",",
"s",
".",
"Signatures",
")",
"\n",
"return",
"&",
"SignedTimestamp",
"{",
"Signatures",
":",
"sigs",
",",
"Signed",
":",
"ts",
",",
"}",
",",
"nil",
"\n",
"}"
] |
// TimestampFromSigned parsed a Signed object into a fully unpacked
// SignedTimestamp
|
[
"TimestampFromSigned",
"parsed",
"a",
"Signed",
"object",
"into",
"a",
"fully",
"unpacked",
"SignedTimestamp"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/timestamp.go#L122-L136
|
train
|
theupdateframework/notary
|
trustmanager/yubikey/import.go
|
Set
|
func (s *YubiImport) Set(name string, bytes []byte) error {
block, _ := pem.Decode(bytes)
if block == nil {
return errors.New("invalid PEM data, could not parse")
}
role, ok := block.Headers["role"]
if !ok {
return errors.New("no role found for key")
}
ki := trustmanager.KeyInfo{
// GUN is ignored by YubiStore
Role: data.RoleName(role),
}
privKey, err := utils.ParsePEMPrivateKey(bytes, "")
if err != nil {
privKey, _, err = trustmanager.GetPasswdDecryptBytes(
s.passRetriever,
bytes,
name,
ki.Role.String(),
)
if err != nil {
return err
}
}
return s.dest.AddKey(ki, privKey)
}
|
go
|
func (s *YubiImport) Set(name string, bytes []byte) error {
block, _ := pem.Decode(bytes)
if block == nil {
return errors.New("invalid PEM data, could not parse")
}
role, ok := block.Headers["role"]
if !ok {
return errors.New("no role found for key")
}
ki := trustmanager.KeyInfo{
// GUN is ignored by YubiStore
Role: data.RoleName(role),
}
privKey, err := utils.ParsePEMPrivateKey(bytes, "")
if err != nil {
privKey, _, err = trustmanager.GetPasswdDecryptBytes(
s.passRetriever,
bytes,
name,
ki.Role.String(),
)
if err != nil {
return err
}
}
return s.dest.AddKey(ki, privKey)
}
|
[
"func",
"(",
"s",
"*",
"YubiImport",
")",
"Set",
"(",
"name",
"string",
",",
"bytes",
"[",
"]",
"byte",
")",
"error",
"{",
"block",
",",
"_",
":=",
"pem",
".",
"Decode",
"(",
"bytes",
")",
"\n",
"if",
"block",
"==",
"nil",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"role",
",",
"ok",
":=",
"block",
".",
"Headers",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"ki",
":=",
"trustmanager",
".",
"KeyInfo",
"{",
"// GUN is ignored by YubiStore",
"Role",
":",
"data",
".",
"RoleName",
"(",
"role",
")",
",",
"}",
"\n",
"privKey",
",",
"err",
":=",
"utils",
".",
"ParsePEMPrivateKey",
"(",
"bytes",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"privKey",
",",
"_",
",",
"err",
"=",
"trustmanager",
".",
"GetPasswdDecryptBytes",
"(",
"s",
".",
"passRetriever",
",",
"bytes",
",",
"name",
",",
"ki",
".",
"Role",
".",
"String",
"(",
")",
",",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"s",
".",
"dest",
".",
"AddKey",
"(",
"ki",
",",
"privKey",
")",
"\n",
"}"
] |
// Set determines if we are allowed to set the given key on the Yubikey and
// calls through to YubiStore.AddKey if it's valid
|
[
"Set",
"determines",
"if",
"we",
"are",
"allowed",
"to",
"set",
"the",
"given",
"key",
"on",
"the",
"Yubikey",
"and",
"calls",
"through",
"to",
"YubiStore",
".",
"AddKey",
"if",
"it",
"s",
"valid"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/trustmanager/yubikey/import.go#L33-L59
|
train
|
theupdateframework/notary
|
server/storage/errors.go
|
Error
|
func (err ErrKeyExists) Error() string {
return fmt.Sprintf("Error, timestamp key already exists for %s:%s", err.gun, err.role)
}
|
go
|
func (err ErrKeyExists) Error() string {
return fmt.Sprintf("Error, timestamp key already exists for %s:%s", err.gun, err.role)
}
|
[
"func",
"(",
"err",
"ErrKeyExists",
")",
"Error",
"(",
")",
"string",
"{",
"return",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"err",
".",
"gun",
",",
"err",
".",
"role",
")",
"\n",
"}"
] |
// ErrKeyExists is returned when a key already exists
|
[
"ErrKeyExists",
"is",
"returned",
"when",
"a",
"key",
"already",
"exists"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/server/storage/errors.go#L30-L32
|
train
|
theupdateframework/notary
|
tuf/data/keys.go
|
IDs
|
func (ks KeyList) IDs() []string {
keyIDs := make([]string, 0, len(ks))
for _, k := range ks {
keyIDs = append(keyIDs, k.ID())
}
return keyIDs
}
|
go
|
func (ks KeyList) IDs() []string {
keyIDs := make([]string, 0, len(ks))
for _, k := range ks {
keyIDs = append(keyIDs, k.ID())
}
return keyIDs
}
|
[
"func",
"(",
"ks",
"KeyList",
")",
"IDs",
"(",
")",
"[",
"]",
"string",
"{",
"keyIDs",
":=",
"make",
"(",
"[",
"]",
"string",
",",
"0",
",",
"len",
"(",
"ks",
")",
")",
"\n",
"for",
"_",
",",
"k",
":=",
"range",
"ks",
"{",
"keyIDs",
"=",
"append",
"(",
"keyIDs",
",",
"k",
".",
"ID",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"keyIDs",
"\n",
"}"
] |
// IDs generates a list of the hex encoded key IDs in the KeyList
|
[
"IDs",
"generates",
"a",
"list",
"of",
"the",
"hex",
"encoded",
"key",
"IDs",
"in",
"the",
"KeyList"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L81-L87
|
train
|
theupdateframework/notary
|
tuf/data/keys.go
|
NewPublicKey
|
func NewPublicKey(alg string, public []byte) PublicKey {
tk := TUFKey{
Type: alg,
Value: KeyPair{
Public: public,
},
}
return typedPublicKey(tk)
}
|
go
|
func NewPublicKey(alg string, public []byte) PublicKey {
tk := TUFKey{
Type: alg,
Value: KeyPair{
Public: public,
},
}
return typedPublicKey(tk)
}
|
[
"func",
"NewPublicKey",
"(",
"alg",
"string",
",",
"public",
"[",
"]",
"byte",
")",
"PublicKey",
"{",
"tk",
":=",
"TUFKey",
"{",
"Type",
":",
"alg",
",",
"Value",
":",
"KeyPair",
"{",
"Public",
":",
"public",
",",
"}",
",",
"}",
"\n",
"return",
"typedPublicKey",
"(",
"tk",
")",
"\n",
"}"
] |
// NewPublicKey creates a new, correctly typed PublicKey, using the
// UnknownPublicKey catchall for unsupported ciphers
|
[
"NewPublicKey",
"creates",
"a",
"new",
"correctly",
"typed",
"PublicKey",
"using",
"the",
"UnknownPublicKey",
"catchall",
"for",
"unsupported",
"ciphers"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L153-L161
|
train
|
theupdateframework/notary
|
tuf/data/keys.go
|
NewPrivateKey
|
func NewPrivateKey(pubKey PublicKey, private []byte) (PrivateKey, error) {
tk := TUFKey{
Type: pubKey.Algorithm(),
Value: KeyPair{
Public: pubKey.Public(),
Private: private, // typedPrivateKey moves this value
},
}
return typedPrivateKey(tk)
}
|
go
|
func NewPrivateKey(pubKey PublicKey, private []byte) (PrivateKey, error) {
tk := TUFKey{
Type: pubKey.Algorithm(),
Value: KeyPair{
Public: pubKey.Public(),
Private: private, // typedPrivateKey moves this value
},
}
return typedPrivateKey(tk)
}
|
[
"func",
"NewPrivateKey",
"(",
"pubKey",
"PublicKey",
",",
"private",
"[",
"]",
"byte",
")",
"(",
"PrivateKey",
",",
"error",
")",
"{",
"tk",
":=",
"TUFKey",
"{",
"Type",
":",
"pubKey",
".",
"Algorithm",
"(",
")",
",",
"Value",
":",
"KeyPair",
"{",
"Public",
":",
"pubKey",
".",
"Public",
"(",
")",
",",
"Private",
":",
"private",
",",
"// typedPrivateKey moves this value",
"}",
",",
"}",
"\n",
"return",
"typedPrivateKey",
"(",
"tk",
")",
"\n",
"}"
] |
// NewPrivateKey creates a new, correctly typed PrivateKey, using the
// UnknownPrivateKey catchall for unsupported ciphers
|
[
"NewPrivateKey",
"creates",
"a",
"new",
"correctly",
"typed",
"PrivateKey",
"using",
"the",
"UnknownPrivateKey",
"catchall",
"for",
"unsupported",
"ciphers"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L165-L174
|
train
|
theupdateframework/notary
|
tuf/data/keys.go
|
UnmarshalPublicKey
|
func UnmarshalPublicKey(data []byte) (PublicKey, error) {
var parsed TUFKey
err := json.Unmarshal(data, &parsed)
if err != nil {
return nil, err
}
return typedPublicKey(parsed), nil
}
|
go
|
func UnmarshalPublicKey(data []byte) (PublicKey, error) {
var parsed TUFKey
err := json.Unmarshal(data, &parsed)
if err != nil {
return nil, err
}
return typedPublicKey(parsed), nil
}
|
[
"func",
"UnmarshalPublicKey",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"PublicKey",
",",
"error",
")",
"{",
"var",
"parsed",
"TUFKey",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"parsed",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"typedPublicKey",
"(",
"parsed",
")",
",",
"nil",
"\n",
"}"
] |
// UnmarshalPublicKey is used to parse individual public keys in JSON
|
[
"UnmarshalPublicKey",
"is",
"used",
"to",
"parse",
"individual",
"public",
"keys",
"in",
"JSON"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L177-L184
|
train
|
theupdateframework/notary
|
tuf/data/keys.go
|
UnmarshalPrivateKey
|
func UnmarshalPrivateKey(data []byte) (PrivateKey, error) {
var parsed TUFKey
err := json.Unmarshal(data, &parsed)
if err != nil {
return nil, err
}
return typedPrivateKey(parsed)
}
|
go
|
func UnmarshalPrivateKey(data []byte) (PrivateKey, error) {
var parsed TUFKey
err := json.Unmarshal(data, &parsed)
if err != nil {
return nil, err
}
return typedPrivateKey(parsed)
}
|
[
"func",
"UnmarshalPrivateKey",
"(",
"data",
"[",
"]",
"byte",
")",
"(",
"PrivateKey",
",",
"error",
")",
"{",
"var",
"parsed",
"TUFKey",
"\n",
"err",
":=",
"json",
".",
"Unmarshal",
"(",
"data",
",",
"&",
"parsed",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"return",
"typedPrivateKey",
"(",
"parsed",
")",
"\n",
"}"
] |
// UnmarshalPrivateKey is used to parse individual private keys in JSON
|
[
"UnmarshalPrivateKey",
"is",
"used",
"to",
"parse",
"individual",
"private",
"keys",
"in",
"JSON"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L187-L194
|
train
|
theupdateframework/notary
|
tuf/data/keys.go
|
ID
|
func (k *TUFKey) ID() string {
if k.id == "" {
pubK := TUFKey{
Type: k.Algorithm(),
Value: KeyPair{
Public: k.Public(),
Private: nil,
},
}
data, err := json.MarshalCanonical(&pubK)
if err != nil {
logrus.Error("Error generating key ID:", err)
}
digest := sha256.Sum256(data)
k.id = hex.EncodeToString(digest[:])
}
return k.id
}
|
go
|
func (k *TUFKey) ID() string {
if k.id == "" {
pubK := TUFKey{
Type: k.Algorithm(),
Value: KeyPair{
Public: k.Public(),
Private: nil,
},
}
data, err := json.MarshalCanonical(&pubK)
if err != nil {
logrus.Error("Error generating key ID:", err)
}
digest := sha256.Sum256(data)
k.id = hex.EncodeToString(digest[:])
}
return k.id
}
|
[
"func",
"(",
"k",
"*",
"TUFKey",
")",
"ID",
"(",
")",
"string",
"{",
"if",
"k",
".",
"id",
"==",
"\"",
"\"",
"{",
"pubK",
":=",
"TUFKey",
"{",
"Type",
":",
"k",
".",
"Algorithm",
"(",
")",
",",
"Value",
":",
"KeyPair",
"{",
"Public",
":",
"k",
".",
"Public",
"(",
")",
",",
"Private",
":",
"nil",
",",
"}",
",",
"}",
"\n",
"data",
",",
"err",
":=",
"json",
".",
"MarshalCanonical",
"(",
"&",
"pubK",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"logrus",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"digest",
":=",
"sha256",
".",
"Sum256",
"(",
"data",
")",
"\n",
"k",
".",
"id",
"=",
"hex",
".",
"EncodeToString",
"(",
"digest",
"[",
":",
"]",
")",
"\n",
"}",
"\n",
"return",
"k",
".",
"id",
"\n",
"}"
] |
// ID efficiently generates if necessary, and caches the ID of the key
|
[
"ID",
"efficiently",
"generates",
"if",
"necessary",
"and",
"caches",
"the",
"ID",
"of",
"the",
"key"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L213-L230
|
train
|
theupdateframework/notary
|
tuf/data/keys.go
|
NewECDSAPublicKey
|
func NewECDSAPublicKey(public []byte) *ECDSAPublicKey {
return &ECDSAPublicKey{
TUFKey: TUFKey{
Type: ECDSAKey,
Value: KeyPair{
Public: public,
Private: nil,
},
},
}
}
|
go
|
func NewECDSAPublicKey(public []byte) *ECDSAPublicKey {
return &ECDSAPublicKey{
TUFKey: TUFKey{
Type: ECDSAKey,
Value: KeyPair{
Public: public,
Private: nil,
},
},
}
}
|
[
"func",
"NewECDSAPublicKey",
"(",
"public",
"[",
"]",
"byte",
")",
"*",
"ECDSAPublicKey",
"{",
"return",
"&",
"ECDSAPublicKey",
"{",
"TUFKey",
":",
"TUFKey",
"{",
"Type",
":",
"ECDSAKey",
",",
"Value",
":",
"KeyPair",
"{",
"Public",
":",
"public",
",",
"Private",
":",
"nil",
",",
"}",
",",
"}",
",",
"}",
"\n",
"}"
] |
// NewECDSAPublicKey initializes a new public key with the ECDSAKey type
|
[
"NewECDSAPublicKey",
"initializes",
"a",
"new",
"public",
"key",
"with",
"the",
"ECDSAKey",
"type"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L275-L285
|
train
|
theupdateframework/notary
|
tuf/data/keys.go
|
NewECDSAx509PublicKey
|
func NewECDSAx509PublicKey(public []byte) *ECDSAx509PublicKey {
return &ECDSAx509PublicKey{
TUFKey: TUFKey{
Type: ECDSAx509Key,
Value: KeyPair{
Public: public,
Private: nil,
},
},
}
}
|
go
|
func NewECDSAx509PublicKey(public []byte) *ECDSAx509PublicKey {
return &ECDSAx509PublicKey{
TUFKey: TUFKey{
Type: ECDSAx509Key,
Value: KeyPair{
Public: public,
Private: nil,
},
},
}
}
|
[
"func",
"NewECDSAx509PublicKey",
"(",
"public",
"[",
"]",
"byte",
")",
"*",
"ECDSAx509PublicKey",
"{",
"return",
"&",
"ECDSAx509PublicKey",
"{",
"TUFKey",
":",
"TUFKey",
"{",
"Type",
":",
"ECDSAx509Key",
",",
"Value",
":",
"KeyPair",
"{",
"Public",
":",
"public",
",",
"Private",
":",
"nil",
",",
"}",
",",
"}",
",",
"}",
"\n",
"}"
] |
// NewECDSAx509PublicKey initializes a new public key with the ECDSAx509Key type
|
[
"NewECDSAx509PublicKey",
"initializes",
"a",
"new",
"public",
"key",
"with",
"the",
"ECDSAx509Key",
"type"
] |
8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5
|
https://github.com/theupdateframework/notary/blob/8ff3ca06ec48f31e1f1d2685e3e6a9f65b6b92b5/tuf/data/keys.go#L288-L298
|
train
|
Subsets and Splits
SQL Console for semeru/code-text-go
Retrieves a limited set of code samples with their languages, with a specific case adjustment for 'Go' language.