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
sequence | docstring
stringlengths 6
2.61k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 85
252
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
cloudflare/cfssl | scan/crypto/tls/common.go | SetSessionTicketKeys | func (c *Config) SetSessionTicketKeys(keys [][32]byte) {
if len(keys) == 0 {
panic("tls: keys must have at least one key")
}
newKeys := make([]ticketKey, len(keys))
for i, bytes := range keys {
newKeys[i] = ticketKeyFromBytes(bytes)
}
c.mutex.Lock()
c.sessionTicketKeys = newKeys
c.mutex.Unlock()
} | go | func (c *Config) SetSessionTicketKeys(keys [][32]byte) {
if len(keys) == 0 {
panic("tls: keys must have at least one key")
}
newKeys := make([]ticketKey, len(keys))
for i, bytes := range keys {
newKeys[i] = ticketKeyFromBytes(bytes)
}
c.mutex.Lock()
c.sessionTicketKeys = newKeys
c.mutex.Unlock()
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"SetSessionTicketKeys",
"(",
"keys",
"[",
"]",
"[",
"32",
"]",
"byte",
")",
"{",
"if",
"len",
"(",
"keys",
")",
"==",
"0",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"newKeys",
":=",
"make",
"(",
"[",
"]",
"ticketKey",
",",
"len",
"(",
"keys",
")",
")",
"\n",
"for",
"i",
",",
"bytes",
":=",
"range",
"keys",
"{",
"newKeys",
"[",
"i",
"]",
"=",
"ticketKeyFromBytes",
"(",
"bytes",
")",
"\n",
"}",
"\n\n",
"c",
".",
"mutex",
".",
"Lock",
"(",
")",
"\n",
"c",
".",
"sessionTicketKeys",
"=",
"newKeys",
"\n",
"c",
".",
"mutex",
".",
"Unlock",
"(",
")",
"\n",
"}"
] | // SetSessionTicketKeys updates the session ticket keys for a server. The first
// key will be used when creating new tickets, while all keys can be used for
// decrypting tickets. It is safe to call this function while the server is
// running in order to rotate the session ticket keys. The function will panic
// if keys is empty. | [
"SetSessionTicketKeys",
"updates",
"the",
"session",
"ticket",
"keys",
"for",
"a",
"server",
".",
"The",
"first",
"key",
"will",
"be",
"used",
"when",
"creating",
"new",
"tickets",
"while",
"all",
"keys",
"can",
"be",
"used",
"for",
"decrypting",
"tickets",
".",
"It",
"is",
"safe",
"to",
"call",
"this",
"function",
"while",
"the",
"server",
"is",
"running",
"in",
"order",
"to",
"rotate",
"the",
"session",
"ticket",
"keys",
".",
"The",
"function",
"will",
"panic",
"if",
"keys",
"is",
"empty",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/tls/common.go#L424-L437 | train |
cloudflare/cfssl | scan/crypto/tls/common.go | mutualVersion | func (c *Config) mutualVersion(vers uint16) (uint16, bool) {
minVersion := c.minVersion()
maxVersion := c.maxVersion()
if vers < minVersion {
return 0, false
}
if vers > maxVersion {
vers = maxVersion
}
return vers, true
} | go | func (c *Config) mutualVersion(vers uint16) (uint16, bool) {
minVersion := c.minVersion()
maxVersion := c.maxVersion()
if vers < minVersion {
return 0, false
}
if vers > maxVersion {
vers = maxVersion
}
return vers, true
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"mutualVersion",
"(",
"vers",
"uint16",
")",
"(",
"uint16",
",",
"bool",
")",
"{",
"minVersion",
":=",
"c",
".",
"minVersion",
"(",
")",
"\n",
"maxVersion",
":=",
"c",
".",
"maxVersion",
"(",
")",
"\n\n",
"if",
"vers",
"<",
"minVersion",
"{",
"return",
"0",
",",
"false",
"\n",
"}",
"\n",
"if",
"vers",
">",
"maxVersion",
"{",
"vers",
"=",
"maxVersion",
"\n",
"}",
"\n",
"return",
"vers",
",",
"true",
"\n",
"}"
] | // mutualVersion returns the protocol version to use given the advertised
// version of the peer. | [
"mutualVersion",
"returns",
"the",
"protocol",
"version",
"to",
"use",
"given",
"the",
"advertised",
"version",
"of",
"the",
"peer",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/tls/common.go#L488-L499 | train |
cloudflare/cfssl | scan/crypto/tls/common.go | getCertificate | func (c *Config) getCertificate(clientHello *ClientHelloInfo) (*Certificate, error) {
if c.GetCertificate != nil &&
(len(c.Certificates) == 0 || len(clientHello.ServerName) > 0) {
cert, err := c.GetCertificate(clientHello)
if cert != nil || err != nil {
return cert, err
}
}
if len(c.Certificates) == 0 {
return nil, errors.New("crypto/tls: no certificates configured")
}
if len(c.Certificates) == 1 || c.NameToCertificate == nil {
// There's only one choice, so no point doing any work.
return &c.Certificates[0], nil
}
name := strings.ToLower(clientHello.ServerName)
for len(name) > 0 && name[len(name)-1] == '.' {
name = name[:len(name)-1]
}
if cert, ok := c.NameToCertificate[name]; ok {
return cert, nil
}
// try replacing labels in the name with wildcards until we get a
// match.
labels := strings.Split(name, ".")
for i := range labels {
labels[i] = "*"
candidate := strings.Join(labels, ".")
if cert, ok := c.NameToCertificate[candidate]; ok {
return cert, nil
}
}
// If nothing matches, return the first certificate.
return &c.Certificates[0], nil
} | go | func (c *Config) getCertificate(clientHello *ClientHelloInfo) (*Certificate, error) {
if c.GetCertificate != nil &&
(len(c.Certificates) == 0 || len(clientHello.ServerName) > 0) {
cert, err := c.GetCertificate(clientHello)
if cert != nil || err != nil {
return cert, err
}
}
if len(c.Certificates) == 0 {
return nil, errors.New("crypto/tls: no certificates configured")
}
if len(c.Certificates) == 1 || c.NameToCertificate == nil {
// There's only one choice, so no point doing any work.
return &c.Certificates[0], nil
}
name := strings.ToLower(clientHello.ServerName)
for len(name) > 0 && name[len(name)-1] == '.' {
name = name[:len(name)-1]
}
if cert, ok := c.NameToCertificate[name]; ok {
return cert, nil
}
// try replacing labels in the name with wildcards until we get a
// match.
labels := strings.Split(name, ".")
for i := range labels {
labels[i] = "*"
candidate := strings.Join(labels, ".")
if cert, ok := c.NameToCertificate[candidate]; ok {
return cert, nil
}
}
// If nothing matches, return the first certificate.
return &c.Certificates[0], nil
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"getCertificate",
"(",
"clientHello",
"*",
"ClientHelloInfo",
")",
"(",
"*",
"Certificate",
",",
"error",
")",
"{",
"if",
"c",
".",
"GetCertificate",
"!=",
"nil",
"&&",
"(",
"len",
"(",
"c",
".",
"Certificates",
")",
"==",
"0",
"||",
"len",
"(",
"clientHello",
".",
"ServerName",
")",
">",
"0",
")",
"{",
"cert",
",",
"err",
":=",
"c",
".",
"GetCertificate",
"(",
"clientHello",
")",
"\n",
"if",
"cert",
"!=",
"nil",
"||",
"err",
"!=",
"nil",
"{",
"return",
"cert",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"c",
".",
"Certificates",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"c",
".",
"Certificates",
")",
"==",
"1",
"||",
"c",
".",
"NameToCertificate",
"==",
"nil",
"{",
"// There's only one choice, so no point doing any work.",
"return",
"&",
"c",
".",
"Certificates",
"[",
"0",
"]",
",",
"nil",
"\n",
"}",
"\n\n",
"name",
":=",
"strings",
".",
"ToLower",
"(",
"clientHello",
".",
"ServerName",
")",
"\n",
"for",
"len",
"(",
"name",
")",
">",
"0",
"&&",
"name",
"[",
"len",
"(",
"name",
")",
"-",
"1",
"]",
"==",
"'.'",
"{",
"name",
"=",
"name",
"[",
":",
"len",
"(",
"name",
")",
"-",
"1",
"]",
"\n",
"}",
"\n\n",
"if",
"cert",
",",
"ok",
":=",
"c",
".",
"NameToCertificate",
"[",
"name",
"]",
";",
"ok",
"{",
"return",
"cert",
",",
"nil",
"\n",
"}",
"\n\n",
"// try replacing labels in the name with wildcards until we get a",
"// match.",
"labels",
":=",
"strings",
".",
"Split",
"(",
"name",
",",
"\"",
"\"",
")",
"\n",
"for",
"i",
":=",
"range",
"labels",
"{",
"labels",
"[",
"i",
"]",
"=",
"\"",
"\"",
"\n",
"candidate",
":=",
"strings",
".",
"Join",
"(",
"labels",
",",
"\"",
"\"",
")",
"\n",
"if",
"cert",
",",
"ok",
":=",
"c",
".",
"NameToCertificate",
"[",
"candidate",
"]",
";",
"ok",
"{",
"return",
"cert",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"// If nothing matches, return the first certificate.",
"return",
"&",
"c",
".",
"Certificates",
"[",
"0",
"]",
",",
"nil",
"\n",
"}"
] | // getCertificate returns the best certificate for the given ClientHelloInfo,
// defaulting to the first element of c.Certificates. | [
"getCertificate",
"returns",
"the",
"best",
"certificate",
"for",
"the",
"given",
"ClientHelloInfo",
"defaulting",
"to",
"the",
"first",
"element",
"of",
"c",
".",
"Certificates",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/tls/common.go#L503-L543 | train |
cloudflare/cfssl | scan/crypto/tls/common.go | BuildNameToCertificate | func (c *Config) BuildNameToCertificate() {
c.NameToCertificate = make(map[string]*Certificate)
for i := range c.Certificates {
cert := &c.Certificates[i]
x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
if err != nil {
continue
}
if len(x509Cert.Subject.CommonName) > 0 {
c.NameToCertificate[x509Cert.Subject.CommonName] = cert
}
for _, san := range x509Cert.DNSNames {
c.NameToCertificate[san] = cert
}
}
} | go | func (c *Config) BuildNameToCertificate() {
c.NameToCertificate = make(map[string]*Certificate)
for i := range c.Certificates {
cert := &c.Certificates[i]
x509Cert, err := x509.ParseCertificate(cert.Certificate[0])
if err != nil {
continue
}
if len(x509Cert.Subject.CommonName) > 0 {
c.NameToCertificate[x509Cert.Subject.CommonName] = cert
}
for _, san := range x509Cert.DNSNames {
c.NameToCertificate[san] = cert
}
}
} | [
"func",
"(",
"c",
"*",
"Config",
")",
"BuildNameToCertificate",
"(",
")",
"{",
"c",
".",
"NameToCertificate",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"Certificate",
")",
"\n",
"for",
"i",
":=",
"range",
"c",
".",
"Certificates",
"{",
"cert",
":=",
"&",
"c",
".",
"Certificates",
"[",
"i",
"]",
"\n",
"x509Cert",
",",
"err",
":=",
"x509",
".",
"ParseCertificate",
"(",
"cert",
".",
"Certificate",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"continue",
"\n",
"}",
"\n",
"if",
"len",
"(",
"x509Cert",
".",
"Subject",
".",
"CommonName",
")",
">",
"0",
"{",
"c",
".",
"NameToCertificate",
"[",
"x509Cert",
".",
"Subject",
".",
"CommonName",
"]",
"=",
"cert",
"\n",
"}",
"\n",
"for",
"_",
",",
"san",
":=",
"range",
"x509Cert",
".",
"DNSNames",
"{",
"c",
".",
"NameToCertificate",
"[",
"san",
"]",
"=",
"cert",
"\n",
"}",
"\n",
"}",
"\n",
"}"
] | // BuildNameToCertificate parses c.Certificates and builds c.NameToCertificate
// from the CommonName and SubjectAlternateName fields of each of the leaf
// certificates. | [
"BuildNameToCertificate",
"parses",
"c",
".",
"Certificates",
"and",
"builds",
"c",
".",
"NameToCertificate",
"from",
"the",
"CommonName",
"and",
"SubjectAlternateName",
"fields",
"of",
"each",
"of",
"the",
"leaf",
"certificates",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/tls/common.go#L548-L563 | train |
cloudflare/cfssl | scan/crypto/tls/common.go | NewLRUClientSessionCache | func NewLRUClientSessionCache(capacity int) ClientSessionCache {
const defaultSessionCacheCapacity = 64
if capacity < 1 {
capacity = defaultSessionCacheCapacity
}
return &lruSessionCache{
m: make(map[string]*list.Element),
q: list.New(),
capacity: capacity,
}
} | go | func NewLRUClientSessionCache(capacity int) ClientSessionCache {
const defaultSessionCacheCapacity = 64
if capacity < 1 {
capacity = defaultSessionCacheCapacity
}
return &lruSessionCache{
m: make(map[string]*list.Element),
q: list.New(),
capacity: capacity,
}
} | [
"func",
"NewLRUClientSessionCache",
"(",
"capacity",
"int",
")",
"ClientSessionCache",
"{",
"const",
"defaultSessionCacheCapacity",
"=",
"64",
"\n\n",
"if",
"capacity",
"<",
"1",
"{",
"capacity",
"=",
"defaultSessionCacheCapacity",
"\n",
"}",
"\n",
"return",
"&",
"lruSessionCache",
"{",
"m",
":",
"make",
"(",
"map",
"[",
"string",
"]",
"*",
"list",
".",
"Element",
")",
",",
"q",
":",
"list",
".",
"New",
"(",
")",
",",
"capacity",
":",
"capacity",
",",
"}",
"\n",
"}"
] | // NewLRUClientSessionCache returns a ClientSessionCache with the given
// capacity that uses an LRU strategy. If capacity is < 1, a default capacity
// is used instead. | [
"NewLRUClientSessionCache",
"returns",
"a",
"ClientSessionCache",
"with",
"the",
"given",
"capacity",
"that",
"uses",
"an",
"LRU",
"strategy",
".",
"If",
"capacity",
"is",
"<",
"1",
"a",
"default",
"capacity",
"is",
"used",
"instead",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/tls/common.go#L617-L628 | train |
cloudflare/cfssl | scan/crypto/tls/cfsslscan_handshake.go | SayHello | func (c *Conn) SayHello(newSigAls []SignatureAndHash) (cipherID, curveType uint16, curveID CurveID, version uint16, certs [][]byte, err error) {
// Set the supported signatures and hashes to the set `newSigAls`
supportedSignatureAlgorithms := make([]signatureAndHash, len(newSigAls))
for i := range newSigAls {
supportedSignatureAlgorithms[i] = newSigAls[i].internal()
}
hello := &clientHelloMsg{
vers: c.config.maxVersion(),
compressionMethods: []uint8{compressionNone},
random: make([]byte, 32),
ocspStapling: true,
serverName: c.config.ServerName,
supportedCurves: c.config.curvePreferences(),
supportedPoints: []uint8{pointFormatUncompressed},
nextProtoNeg: len(c.config.NextProtos) > 0,
secureRenegotiation: true,
cipherSuites: c.config.cipherSuites(),
signatureAndHashes: supportedSignatureAlgorithms,
}
serverHello, err := c.sayHello(hello)
if err != nil {
return
}
// Prime the connection, if necessary, for key
// exchange messages by reading off the certificate
// message and, if necessary, the OCSP stapling
// message
var msg interface{}
msg, err = c.readHandshake()
if err != nil {
return
}
certMsg, ok := msg.(*certificateMsg)
if !ok || len(certMsg.certificates) == 0 {
err = unexpectedMessageError(certMsg, msg)
return
}
certs = certMsg.certificates
if serverHello.ocspStapling {
msg, err = c.readHandshake()
if err != nil {
return
}
certStatusMsg, ok := msg.(*certificateStatusMsg)
if !ok {
err = unexpectedMessageError(certStatusMsg, msg)
return
}
}
if CipherSuites[serverHello.cipherSuite].EllipticCurve {
var skx *serverKeyExchangeMsg
skx, err = c.exchangeKeys()
if err != nil {
return
}
if skx.raw[0] != typeServerKeyExchange {
err = unexpectedMessageError(skx, msg)
return
}
if len(skx.key) < 4 {
err = unexpectedMessageError(skx, msg)
return
}
curveType = uint16(skx.key[0])
// If we have a named curve, report which one it is.
if curveType == 3 {
curveID = CurveID(skx.key[1])<<8 | CurveID(skx.key[2])
}
}
cipherID, version = serverHello.cipherSuite, serverHello.vers
return
} | go | func (c *Conn) SayHello(newSigAls []SignatureAndHash) (cipherID, curveType uint16, curveID CurveID, version uint16, certs [][]byte, err error) {
// Set the supported signatures and hashes to the set `newSigAls`
supportedSignatureAlgorithms := make([]signatureAndHash, len(newSigAls))
for i := range newSigAls {
supportedSignatureAlgorithms[i] = newSigAls[i].internal()
}
hello := &clientHelloMsg{
vers: c.config.maxVersion(),
compressionMethods: []uint8{compressionNone},
random: make([]byte, 32),
ocspStapling: true,
serverName: c.config.ServerName,
supportedCurves: c.config.curvePreferences(),
supportedPoints: []uint8{pointFormatUncompressed},
nextProtoNeg: len(c.config.NextProtos) > 0,
secureRenegotiation: true,
cipherSuites: c.config.cipherSuites(),
signatureAndHashes: supportedSignatureAlgorithms,
}
serverHello, err := c.sayHello(hello)
if err != nil {
return
}
// Prime the connection, if necessary, for key
// exchange messages by reading off the certificate
// message and, if necessary, the OCSP stapling
// message
var msg interface{}
msg, err = c.readHandshake()
if err != nil {
return
}
certMsg, ok := msg.(*certificateMsg)
if !ok || len(certMsg.certificates) == 0 {
err = unexpectedMessageError(certMsg, msg)
return
}
certs = certMsg.certificates
if serverHello.ocspStapling {
msg, err = c.readHandshake()
if err != nil {
return
}
certStatusMsg, ok := msg.(*certificateStatusMsg)
if !ok {
err = unexpectedMessageError(certStatusMsg, msg)
return
}
}
if CipherSuites[serverHello.cipherSuite].EllipticCurve {
var skx *serverKeyExchangeMsg
skx, err = c.exchangeKeys()
if err != nil {
return
}
if skx.raw[0] != typeServerKeyExchange {
err = unexpectedMessageError(skx, msg)
return
}
if len(skx.key) < 4 {
err = unexpectedMessageError(skx, msg)
return
}
curveType = uint16(skx.key[0])
// If we have a named curve, report which one it is.
if curveType == 3 {
curveID = CurveID(skx.key[1])<<8 | CurveID(skx.key[2])
}
}
cipherID, version = serverHello.cipherSuite, serverHello.vers
return
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"SayHello",
"(",
"newSigAls",
"[",
"]",
"SignatureAndHash",
")",
"(",
"cipherID",
",",
"curveType",
"uint16",
",",
"curveID",
"CurveID",
",",
"version",
"uint16",
",",
"certs",
"[",
"]",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"// Set the supported signatures and hashes to the set `newSigAls`",
"supportedSignatureAlgorithms",
":=",
"make",
"(",
"[",
"]",
"signatureAndHash",
",",
"len",
"(",
"newSigAls",
")",
")",
"\n",
"for",
"i",
":=",
"range",
"newSigAls",
"{",
"supportedSignatureAlgorithms",
"[",
"i",
"]",
"=",
"newSigAls",
"[",
"i",
"]",
".",
"internal",
"(",
")",
"\n",
"}",
"\n\n",
"hello",
":=",
"&",
"clientHelloMsg",
"{",
"vers",
":",
"c",
".",
"config",
".",
"maxVersion",
"(",
")",
",",
"compressionMethods",
":",
"[",
"]",
"uint8",
"{",
"compressionNone",
"}",
",",
"random",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"32",
")",
",",
"ocspStapling",
":",
"true",
",",
"serverName",
":",
"c",
".",
"config",
".",
"ServerName",
",",
"supportedCurves",
":",
"c",
".",
"config",
".",
"curvePreferences",
"(",
")",
",",
"supportedPoints",
":",
"[",
"]",
"uint8",
"{",
"pointFormatUncompressed",
"}",
",",
"nextProtoNeg",
":",
"len",
"(",
"c",
".",
"config",
".",
"NextProtos",
")",
">",
"0",
",",
"secureRenegotiation",
":",
"true",
",",
"cipherSuites",
":",
"c",
".",
"config",
".",
"cipherSuites",
"(",
")",
",",
"signatureAndHashes",
":",
"supportedSignatureAlgorithms",
",",
"}",
"\n",
"serverHello",
",",
"err",
":=",
"c",
".",
"sayHello",
"(",
"hello",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// Prime the connection, if necessary, for key",
"// exchange messages by reading off the certificate",
"// message and, if necessary, the OCSP stapling",
"// message",
"var",
"msg",
"interface",
"{",
"}",
"\n",
"msg",
",",
"err",
"=",
"c",
".",
"readHandshake",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"certMsg",
",",
"ok",
":=",
"msg",
".",
"(",
"*",
"certificateMsg",
")",
"\n",
"if",
"!",
"ok",
"||",
"len",
"(",
"certMsg",
".",
"certificates",
")",
"==",
"0",
"{",
"err",
"=",
"unexpectedMessageError",
"(",
"certMsg",
",",
"msg",
")",
"\n",
"return",
"\n",
"}",
"\n",
"certs",
"=",
"certMsg",
".",
"certificates",
"\n\n",
"if",
"serverHello",
".",
"ocspStapling",
"{",
"msg",
",",
"err",
"=",
"c",
".",
"readHandshake",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"certStatusMsg",
",",
"ok",
":=",
"msg",
".",
"(",
"*",
"certificateStatusMsg",
")",
"\n",
"if",
"!",
"ok",
"{",
"err",
"=",
"unexpectedMessageError",
"(",
"certStatusMsg",
",",
"msg",
")",
"\n",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"CipherSuites",
"[",
"serverHello",
".",
"cipherSuite",
"]",
".",
"EllipticCurve",
"{",
"var",
"skx",
"*",
"serverKeyExchangeMsg",
"\n",
"skx",
",",
"err",
"=",
"c",
".",
"exchangeKeys",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"skx",
".",
"raw",
"[",
"0",
"]",
"!=",
"typeServerKeyExchange",
"{",
"err",
"=",
"unexpectedMessageError",
"(",
"skx",
",",
"msg",
")",
"\n",
"return",
"\n",
"}",
"\n",
"if",
"len",
"(",
"skx",
".",
"key",
")",
"<",
"4",
"{",
"err",
"=",
"unexpectedMessageError",
"(",
"skx",
",",
"msg",
")",
"\n",
"return",
"\n",
"}",
"\n",
"curveType",
"=",
"uint16",
"(",
"skx",
".",
"key",
"[",
"0",
"]",
")",
"\n",
"// If we have a named curve, report which one it is.",
"if",
"curveType",
"==",
"3",
"{",
"curveID",
"=",
"CurveID",
"(",
"skx",
".",
"key",
"[",
"1",
"]",
")",
"<<",
"8",
"|",
"CurveID",
"(",
"skx",
".",
"key",
"[",
"2",
"]",
")",
"\n",
"}",
"\n",
"}",
"\n",
"cipherID",
",",
"version",
"=",
"serverHello",
".",
"cipherSuite",
",",
"serverHello",
".",
"vers",
"\n\n",
"return",
"\n",
"}"
] | // SayHello constructs a simple Client Hello to a server, parses its serverHelloMsg response
// and returns the negotiated ciphersuite ID, and, if an EC cipher suite, the curve ID | [
"SayHello",
"constructs",
"a",
"simple",
"Client",
"Hello",
"to",
"a",
"server",
"parses",
"its",
"serverHelloMsg",
"response",
"and",
"returns",
"the",
"negotiated",
"ciphersuite",
"ID",
"and",
"if",
"an",
"EC",
"cipher",
"suite",
"the",
"curve",
"ID"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/tls/cfsslscan_handshake.go#L5-L81 | train |
cloudflare/cfssl | scan/crypto/tls/cfsslscan_handshake.go | sayHello | func (c *Conn) sayHello(hello *clientHelloMsg) (serverHello *serverHelloMsg, err error) {
c.writeRecord(recordTypeHandshake, hello.marshal())
msg, err := c.readHandshake()
if err != nil {
return
}
serverHello, ok := msg.(*serverHelloMsg)
if !ok {
return nil, unexpectedMessageError(serverHello, msg)
}
return
} | go | func (c *Conn) sayHello(hello *clientHelloMsg) (serverHello *serverHelloMsg, err error) {
c.writeRecord(recordTypeHandshake, hello.marshal())
msg, err := c.readHandshake()
if err != nil {
return
}
serverHello, ok := msg.(*serverHelloMsg)
if !ok {
return nil, unexpectedMessageError(serverHello, msg)
}
return
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"sayHello",
"(",
"hello",
"*",
"clientHelloMsg",
")",
"(",
"serverHello",
"*",
"serverHelloMsg",
",",
"err",
"error",
")",
"{",
"c",
".",
"writeRecord",
"(",
"recordTypeHandshake",
",",
"hello",
".",
"marshal",
"(",
")",
")",
"\n",
"msg",
",",
"err",
":=",
"c",
".",
"readHandshake",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"serverHello",
",",
"ok",
":=",
"msg",
".",
"(",
"*",
"serverHelloMsg",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"unexpectedMessageError",
"(",
"serverHello",
",",
"msg",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // sayHello is the backend to SayHello that returns a full serverHelloMsg for processing. | [
"sayHello",
"is",
"the",
"backend",
"to",
"SayHello",
"that",
"returns",
"a",
"full",
"serverHelloMsg",
"for",
"processing",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/tls/cfsslscan_handshake.go#L84-L95 | train |
cloudflare/cfssl | scan/crypto/tls/cfsslscan_handshake.go | exchangeKeys | func (c *Conn) exchangeKeys() (serverKeyExchange *serverKeyExchangeMsg, err error) {
msg, err := c.readHandshake()
if err != nil {
return
}
serverKeyExchange, ok := msg.(*serverKeyExchangeMsg)
if !ok {
return nil, unexpectedMessageError(serverKeyExchange, msg)
}
return
} | go | func (c *Conn) exchangeKeys() (serverKeyExchange *serverKeyExchangeMsg, err error) {
msg, err := c.readHandshake()
if err != nil {
return
}
serverKeyExchange, ok := msg.(*serverKeyExchangeMsg)
if !ok {
return nil, unexpectedMessageError(serverKeyExchange, msg)
}
return
} | [
"func",
"(",
"c",
"*",
"Conn",
")",
"exchangeKeys",
"(",
")",
"(",
"serverKeyExchange",
"*",
"serverKeyExchangeMsg",
",",
"err",
"error",
")",
"{",
"msg",
",",
"err",
":=",
"c",
".",
"readHandshake",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"serverKeyExchange",
",",
"ok",
":=",
"msg",
".",
"(",
"*",
"serverKeyExchangeMsg",
")",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"unexpectedMessageError",
"(",
"serverKeyExchange",
",",
"msg",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // exchangeKeys continues the handshake to receive the serverKeyExchange message,
// from which we can extract elliptic curve parameters | [
"exchangeKeys",
"continues",
"the",
"handshake",
"to",
"receive",
"the",
"serverKeyExchange",
"message",
"from",
"which",
"we",
"can",
"extract",
"elliptic",
"curve",
"parameters"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/tls/cfsslscan_handshake.go#L99-L109 | train |
cloudflare/cfssl | bundler/bundle.go | PemBlockToString | func PemBlockToString(block *pem.Block) string {
if block.Bytes == nil || block.Type == "" {
return ""
}
return string(bytes.TrimSpace(pem.EncodeToMemory(block)))
} | go | func PemBlockToString(block *pem.Block) string {
if block.Bytes == nil || block.Type == "" {
return ""
}
return string(bytes.TrimSpace(pem.EncodeToMemory(block)))
} | [
"func",
"PemBlockToString",
"(",
"block",
"*",
"pem",
".",
"Block",
")",
"string",
"{",
"if",
"block",
".",
"Bytes",
"==",
"nil",
"||",
"block",
".",
"Type",
"==",
"\"",
"\"",
"{",
"return",
"\"",
"\"",
"\n",
"}",
"\n",
"return",
"string",
"(",
"bytes",
".",
"TrimSpace",
"(",
"pem",
".",
"EncodeToMemory",
"(",
"block",
")",
")",
")",
"\n",
"}"
] | // PemBlockToString turns a pem.Block into the string encoded form. | [
"PemBlockToString",
"turns",
"a",
"pem",
".",
"Block",
"into",
"the",
"string",
"encoded",
"form",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/bundler/bundle.go#L61-L66 | train |
cloudflare/cfssl | bundler/bundle.go | buildHostnames | func (b *Bundle) buildHostnames() {
if b.Cert == nil {
return
}
// hset keeps a set of unique hostnames.
hset := make(map[string]bool)
// insert CN into hset
if b.Cert.Subject.CommonName != "" {
hset[b.Cert.Subject.CommonName] = true
}
// insert all DNS names into hset
for _, h := range b.Cert.DNSNames {
hset[h] = true
}
// convert hset to an array of hostnames
b.Hostnames = make([]string, len(hset))
i := 0
for h := range hset {
b.Hostnames[i] = h
i++
}
} | go | func (b *Bundle) buildHostnames() {
if b.Cert == nil {
return
}
// hset keeps a set of unique hostnames.
hset := make(map[string]bool)
// insert CN into hset
if b.Cert.Subject.CommonName != "" {
hset[b.Cert.Subject.CommonName] = true
}
// insert all DNS names into hset
for _, h := range b.Cert.DNSNames {
hset[h] = true
}
// convert hset to an array of hostnames
b.Hostnames = make([]string, len(hset))
i := 0
for h := range hset {
b.Hostnames[i] = h
i++
}
} | [
"func",
"(",
"b",
"*",
"Bundle",
")",
"buildHostnames",
"(",
")",
"{",
"if",
"b",
".",
"Cert",
"==",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"// hset keeps a set of unique hostnames.",
"hset",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"bool",
")",
"\n",
"// insert CN into hset",
"if",
"b",
".",
"Cert",
".",
"Subject",
".",
"CommonName",
"!=",
"\"",
"\"",
"{",
"hset",
"[",
"b",
".",
"Cert",
".",
"Subject",
".",
"CommonName",
"]",
"=",
"true",
"\n",
"}",
"\n",
"// insert all DNS names into hset",
"for",
"_",
",",
"h",
":=",
"range",
"b",
".",
"Cert",
".",
"DNSNames",
"{",
"hset",
"[",
"h",
"]",
"=",
"true",
"\n",
"}",
"\n\n",
"// convert hset to an array of hostnames",
"b",
".",
"Hostnames",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"hset",
")",
")",
"\n",
"i",
":=",
"0",
"\n",
"for",
"h",
":=",
"range",
"hset",
"{",
"b",
".",
"Hostnames",
"[",
"i",
"]",
"=",
"h",
"\n",
"i",
"++",
"\n",
"}",
"\n",
"}"
] | // buildHostnames sets bundle.Hostnames by the x509 cert's subject CN and DNS names
// Since the subject CN may overlap with one of the DNS names, it needs to handle
// the duplication by a set. | [
"buildHostnames",
"sets",
"bundle",
".",
"Hostnames",
"by",
"the",
"x509",
"cert",
"s",
"subject",
"CN",
"and",
"DNS",
"names",
"Since",
"the",
"subject",
"CN",
"may",
"overlap",
"with",
"one",
"of",
"the",
"DNS",
"names",
"it",
"needs",
"to",
"handle",
"the",
"duplication",
"by",
"a",
"set",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/bundler/bundle.go#L164-L186 | train |
cloudflare/cfssl | transport/roots/cfssl.go | NewCFSSL | func NewCFSSL(metadata map[string]string) ([]*x509.Certificate, error) {
host, ok := metadata["host"]
if !ok {
return nil, errors.New("transport: CFSSL root provider requires a host")
}
label := metadata["label"]
profile := metadata["profile"]
cert, err := helpers.LoadClientCertificate(metadata["mutual-tls-cert"], metadata["mutual-tls-key"])
if err != nil {
return nil, err
}
remoteCAs, err := helpers.LoadPEMCertPool(metadata["tls-remote-ca"])
if err != nil {
return nil, err
}
srv := client.NewServerTLS(host, helpers.CreateTLSConfig(remoteCAs, cert))
data, err := json.Marshal(info.Req{Label: label, Profile: profile})
if err != nil {
return nil, err
}
resp, err := srv.Info(data)
if err != nil {
return nil, err
}
return helpers.ParseCertificatesPEM([]byte(resp.Certificate))
} | go | func NewCFSSL(metadata map[string]string) ([]*x509.Certificate, error) {
host, ok := metadata["host"]
if !ok {
return nil, errors.New("transport: CFSSL root provider requires a host")
}
label := metadata["label"]
profile := metadata["profile"]
cert, err := helpers.LoadClientCertificate(metadata["mutual-tls-cert"], metadata["mutual-tls-key"])
if err != nil {
return nil, err
}
remoteCAs, err := helpers.LoadPEMCertPool(metadata["tls-remote-ca"])
if err != nil {
return nil, err
}
srv := client.NewServerTLS(host, helpers.CreateTLSConfig(remoteCAs, cert))
data, err := json.Marshal(info.Req{Label: label, Profile: profile})
if err != nil {
return nil, err
}
resp, err := srv.Info(data)
if err != nil {
return nil, err
}
return helpers.ParseCertificatesPEM([]byte(resp.Certificate))
} | [
"func",
"NewCFSSL",
"(",
"metadata",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"[",
"]",
"*",
"x509",
".",
"Certificate",
",",
"error",
")",
"{",
"host",
",",
"ok",
":=",
"metadata",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"label",
":=",
"metadata",
"[",
"\"",
"\"",
"]",
"\n",
"profile",
":=",
"metadata",
"[",
"\"",
"\"",
"]",
"\n",
"cert",
",",
"err",
":=",
"helpers",
".",
"LoadClientCertificate",
"(",
"metadata",
"[",
"\"",
"\"",
"]",
",",
"metadata",
"[",
"\"",
"\"",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"remoteCAs",
",",
"err",
":=",
"helpers",
".",
"LoadPEMCertPool",
"(",
"metadata",
"[",
"\"",
"\"",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"srv",
":=",
"client",
".",
"NewServerTLS",
"(",
"host",
",",
"helpers",
".",
"CreateTLSConfig",
"(",
"remoteCAs",
",",
"cert",
")",
")",
"\n",
"data",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"info",
".",
"Req",
"{",
"Label",
":",
"label",
",",
"Profile",
":",
"profile",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"srv",
".",
"Info",
"(",
"data",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"helpers",
".",
"ParseCertificatesPEM",
"(",
"[",
"]",
"byte",
"(",
"resp",
".",
"Certificate",
")",
")",
"\n",
"}"
] | // This package contains CFSSL integration.
// NewCFSSL produces a new CFSSL root. | [
"This",
"package",
"contains",
"CFSSL",
"integration",
".",
"NewCFSSL",
"produces",
"a",
"new",
"CFSSL",
"root",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/transport/roots/cfssl.go#L16-L44 | train |
cloudflare/cfssl | helpers/derhelpers/ed25519.go | ParseEd25519PublicKey | func ParseEd25519PublicKey(der []byte) (crypto.PublicKey, error) {
var spki subjectPublicKeyInfo
if rest, err := asn1.Unmarshal(der, &spki); err != nil {
return nil, err
} else if len(rest) > 0 {
return nil, errors.New("SubjectPublicKeyInfo too long")
}
if !spki.Algorithm.Algorithm.Equal(ed25519OID) {
return nil, errEd25519WrongID
}
if spki.PublicKey.BitLength != ed25519.PublicKeySize*8 {
return nil, errors.New("SubjectPublicKeyInfo PublicKey length mismatch")
}
return ed25519.PublicKey(spki.PublicKey.Bytes), nil
} | go | func ParseEd25519PublicKey(der []byte) (crypto.PublicKey, error) {
var spki subjectPublicKeyInfo
if rest, err := asn1.Unmarshal(der, &spki); err != nil {
return nil, err
} else if len(rest) > 0 {
return nil, errors.New("SubjectPublicKeyInfo too long")
}
if !spki.Algorithm.Algorithm.Equal(ed25519OID) {
return nil, errEd25519WrongID
}
if spki.PublicKey.BitLength != ed25519.PublicKeySize*8 {
return nil, errors.New("SubjectPublicKeyInfo PublicKey length mismatch")
}
return ed25519.PublicKey(spki.PublicKey.Bytes), nil
} | [
"func",
"ParseEd25519PublicKey",
"(",
"der",
"[",
"]",
"byte",
")",
"(",
"crypto",
".",
"PublicKey",
",",
"error",
")",
"{",
"var",
"spki",
"subjectPublicKeyInfo",
"\n",
"if",
"rest",
",",
"err",
":=",
"asn1",
".",
"Unmarshal",
"(",
"der",
",",
"&",
"spki",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"len",
"(",
"rest",
")",
">",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"spki",
".",
"Algorithm",
".",
"Algorithm",
".",
"Equal",
"(",
"ed25519OID",
")",
"{",
"return",
"nil",
",",
"errEd25519WrongID",
"\n",
"}",
"\n\n",
"if",
"spki",
".",
"PublicKey",
".",
"BitLength",
"!=",
"ed25519",
".",
"PublicKeySize",
"*",
"8",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"ed25519",
".",
"PublicKey",
"(",
"spki",
".",
"PublicKey",
".",
"Bytes",
")",
",",
"nil",
"\n",
"}"
] | // ParseEd25519PublicKey returns the Ed25519 public key encoded by the input. | [
"ParseEd25519PublicKey",
"returns",
"the",
"Ed25519",
"public",
"key",
"encoded",
"by",
"the",
"input",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/helpers/derhelpers/ed25519.go#L51-L68 | train |
cloudflare/cfssl | helpers/derhelpers/ed25519.go | ParseEd25519PrivateKey | func ParseEd25519PrivateKey(der []byte) (crypto.PrivateKey, error) {
asym := new(oneAsymmetricKey)
if rest, err := asn1.Unmarshal(der, asym); err != nil {
return nil, err
} else if len(rest) > 0 {
return nil, errors.New("OneAsymmetricKey too long")
}
// Check that the key type is correct.
if !asym.Algorithm.Algorithm.Equal(ed25519OID) {
return nil, errEd25519WrongID
}
// Unmarshal the inner CurvePrivateKey.
seed := new(curvePrivateKey)
if rest, err := asn1.Unmarshal(asym.PrivateKey, seed); err != nil {
return nil, err
} else if len(rest) > 0 {
return nil, errors.New("CurvePrivateKey too long")
}
return ed25519.NewKeyFromSeed(*seed), nil
} | go | func ParseEd25519PrivateKey(der []byte) (crypto.PrivateKey, error) {
asym := new(oneAsymmetricKey)
if rest, err := asn1.Unmarshal(der, asym); err != nil {
return nil, err
} else if len(rest) > 0 {
return nil, errors.New("OneAsymmetricKey too long")
}
// Check that the key type is correct.
if !asym.Algorithm.Algorithm.Equal(ed25519OID) {
return nil, errEd25519WrongID
}
// Unmarshal the inner CurvePrivateKey.
seed := new(curvePrivateKey)
if rest, err := asn1.Unmarshal(asym.PrivateKey, seed); err != nil {
return nil, err
} else if len(rest) > 0 {
return nil, errors.New("CurvePrivateKey too long")
}
return ed25519.NewKeyFromSeed(*seed), nil
} | [
"func",
"ParseEd25519PrivateKey",
"(",
"der",
"[",
"]",
"byte",
")",
"(",
"crypto",
".",
"PrivateKey",
",",
"error",
")",
"{",
"asym",
":=",
"new",
"(",
"oneAsymmetricKey",
")",
"\n",
"if",
"rest",
",",
"err",
":=",
"asn1",
".",
"Unmarshal",
"(",
"der",
",",
"asym",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"len",
"(",
"rest",
")",
">",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check that the key type is correct.",
"if",
"!",
"asym",
".",
"Algorithm",
".",
"Algorithm",
".",
"Equal",
"(",
"ed25519OID",
")",
"{",
"return",
"nil",
",",
"errEd25519WrongID",
"\n",
"}",
"\n\n",
"// Unmarshal the inner CurvePrivateKey.",
"seed",
":=",
"new",
"(",
"curvePrivateKey",
")",
"\n",
"if",
"rest",
",",
"err",
":=",
"asn1",
".",
"Unmarshal",
"(",
"asym",
".",
"PrivateKey",
",",
"seed",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"len",
"(",
"rest",
")",
">",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"ed25519",
".",
"NewKeyFromSeed",
"(",
"*",
"seed",
")",
",",
"nil",
"\n",
"}"
] | // ParseEd25519PrivateKey returns the Ed25519 private key encoded by the input. | [
"ParseEd25519PrivateKey",
"returns",
"the",
"Ed25519",
"private",
"key",
"encoded",
"by",
"the",
"input",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/helpers/derhelpers/ed25519.go#L111-L133 | train |
cloudflare/cfssl | cli/cli.go | PopFirstArgument | func PopFirstArgument(args []string) (string, []string, error) {
if len(args) < 1 {
return "", nil, errors.New("not enough arguments are supplied --- please refer to the usage")
}
return args[0], args[1:], nil
} | go | func PopFirstArgument(args []string) (string, []string, error) {
if len(args) < 1 {
return "", nil, errors.New("not enough arguments are supplied --- please refer to the usage")
}
return args[0], args[1:], nil
} | [
"func",
"PopFirstArgument",
"(",
"args",
"[",
"]",
"string",
")",
"(",
"string",
",",
"[",
"]",
"string",
",",
"error",
")",
"{",
"if",
"len",
"(",
"args",
")",
"<",
"1",
"{",
"return",
"\"",
"\"",
",",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"return",
"args",
"[",
"0",
"]",
",",
"args",
"[",
"1",
":",
"]",
",",
"nil",
"\n",
"}"
] | // PopFirstArgument returns the first element and the rest of a string
// slice and return error if failed to do so. It is a helper function
// to parse non-flag arguments previously used in cfssl commands. | [
"PopFirstArgument",
"returns",
"the",
"first",
"element",
"and",
"the",
"rest",
"of",
"a",
"string",
"slice",
"and",
"return",
"error",
"if",
"failed",
"to",
"do",
"so",
".",
"It",
"is",
"a",
"helper",
"function",
"to",
"parse",
"non",
"-",
"flag",
"arguments",
"previously",
"used",
"in",
"cfssl",
"commands",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/cli/cli.go#L74-L79 | train |
cloudflare/cfssl | cli/cli.go | Start | func Start(cmds map[string]*Command) error {
// cfsslFlagSet is the flag sets for cfssl.
var cfsslFlagSet = flag.NewFlagSet("cfssl", flag.ExitOnError)
var c Config
registerFlags(&c, cfsslFlagSet)
// Initial parse of command line arguments. By convention, only -h/-help is supported.
if flag.Usage == nil {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, usage)
for name := range cmds {
fmt.Fprintf(os.Stderr, "\t%s\n", name)
}
fmt.Fprintf(os.Stderr, "Top-level flags:\n")
flag.PrintDefaults()
}
}
flag.Parse()
if flag.NArg() < 1 {
fmt.Fprintf(os.Stderr, "No command is given.\n")
flag.Usage()
return errors.New("no command was given")
}
// Clip out the command name and args for the command
cmdName = flag.Arg(0)
args := flag.Args()[1:]
cmd, found := cmds[cmdName]
if !found {
fmt.Fprintf(os.Stderr, "Command %s is not defined.\n", cmdName)
flag.Usage()
return errors.New("undefined command")
}
// always have flag 'loglevel' for each command
cmd.Flags = append(cmd.Flags, "loglevel")
// The usage of each individual command is re-written to mention
// flags defined and referenced only in that command.
cfsslFlagSet.Usage = func() {
fmt.Fprintf(os.Stderr, "\t%s", cmd.UsageText)
for _, name := range cmd.Flags {
if f := cfsslFlagSet.Lookup(name); f != nil {
printDefaultValue(f)
}
}
}
// Parse all flags and take the rest as argument lists for the command
cfsslFlagSet.Parse(args)
args = cfsslFlagSet.Args()
var err error
if c.ConfigFile != "" {
c.CFG, err = config.LoadFile(c.ConfigFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load config file: %v", err)
return errors.New("failed to load config file")
}
}
if err := cmd.Main(args, c); err != nil {
fmt.Fprintln(os.Stderr, err)
return err
}
return nil
} | go | func Start(cmds map[string]*Command) error {
// cfsslFlagSet is the flag sets for cfssl.
var cfsslFlagSet = flag.NewFlagSet("cfssl", flag.ExitOnError)
var c Config
registerFlags(&c, cfsslFlagSet)
// Initial parse of command line arguments. By convention, only -h/-help is supported.
if flag.Usage == nil {
flag.Usage = func() {
fmt.Fprintf(os.Stderr, usage)
for name := range cmds {
fmt.Fprintf(os.Stderr, "\t%s\n", name)
}
fmt.Fprintf(os.Stderr, "Top-level flags:\n")
flag.PrintDefaults()
}
}
flag.Parse()
if flag.NArg() < 1 {
fmt.Fprintf(os.Stderr, "No command is given.\n")
flag.Usage()
return errors.New("no command was given")
}
// Clip out the command name and args for the command
cmdName = flag.Arg(0)
args := flag.Args()[1:]
cmd, found := cmds[cmdName]
if !found {
fmt.Fprintf(os.Stderr, "Command %s is not defined.\n", cmdName)
flag.Usage()
return errors.New("undefined command")
}
// always have flag 'loglevel' for each command
cmd.Flags = append(cmd.Flags, "loglevel")
// The usage of each individual command is re-written to mention
// flags defined and referenced only in that command.
cfsslFlagSet.Usage = func() {
fmt.Fprintf(os.Stderr, "\t%s", cmd.UsageText)
for _, name := range cmd.Flags {
if f := cfsslFlagSet.Lookup(name); f != nil {
printDefaultValue(f)
}
}
}
// Parse all flags and take the rest as argument lists for the command
cfsslFlagSet.Parse(args)
args = cfsslFlagSet.Args()
var err error
if c.ConfigFile != "" {
c.CFG, err = config.LoadFile(c.ConfigFile)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to load config file: %v", err)
return errors.New("failed to load config file")
}
}
if err := cmd.Main(args, c); err != nil {
fmt.Fprintln(os.Stderr, err)
return err
}
return nil
} | [
"func",
"Start",
"(",
"cmds",
"map",
"[",
"string",
"]",
"*",
"Command",
")",
"error",
"{",
"// cfsslFlagSet is the flag sets for cfssl.",
"var",
"cfsslFlagSet",
"=",
"flag",
".",
"NewFlagSet",
"(",
"\"",
"\"",
",",
"flag",
".",
"ExitOnError",
")",
"\n",
"var",
"c",
"Config",
"\n\n",
"registerFlags",
"(",
"&",
"c",
",",
"cfsslFlagSet",
")",
"\n",
"// Initial parse of command line arguments. By convention, only -h/-help is supported.",
"if",
"flag",
".",
"Usage",
"==",
"nil",
"{",
"flag",
".",
"Usage",
"=",
"func",
"(",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"usage",
")",
"\n",
"for",
"name",
":=",
"range",
"cmds",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\t",
"\\n",
"\"",
",",
"name",
")",
"\n",
"}",
"\n",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"flag",
".",
"PrintDefaults",
"(",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"flag",
".",
"Parse",
"(",
")",
"\n\n",
"if",
"flag",
".",
"NArg",
"(",
")",
"<",
"1",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
")",
"\n",
"flag",
".",
"Usage",
"(",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Clip out the command name and args for the command",
"cmdName",
"=",
"flag",
".",
"Arg",
"(",
"0",
")",
"\n",
"args",
":=",
"flag",
".",
"Args",
"(",
")",
"[",
"1",
":",
"]",
"\n",
"cmd",
",",
"found",
":=",
"cmds",
"[",
"cmdName",
"]",
"\n",
"if",
"!",
"found",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\n",
"\"",
",",
"cmdName",
")",
"\n",
"flag",
".",
"Usage",
"(",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"// always have flag 'loglevel' for each command",
"cmd",
".",
"Flags",
"=",
"append",
"(",
"cmd",
".",
"Flags",
",",
"\"",
"\"",
")",
"\n",
"// The usage of each individual command is re-written to mention",
"// flags defined and referenced only in that command.",
"cfsslFlagSet",
".",
"Usage",
"=",
"func",
"(",
")",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\\t",
"\"",
",",
"cmd",
".",
"UsageText",
")",
"\n",
"for",
"_",
",",
"name",
":=",
"range",
"cmd",
".",
"Flags",
"{",
"if",
"f",
":=",
"cfsslFlagSet",
".",
"Lookup",
"(",
"name",
")",
";",
"f",
"!=",
"nil",
"{",
"printDefaultValue",
"(",
"f",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n\n",
"// Parse all flags and take the rest as argument lists for the command",
"cfsslFlagSet",
".",
"Parse",
"(",
"args",
")",
"\n",
"args",
"=",
"cfsslFlagSet",
".",
"Args",
"(",
")",
"\n\n",
"var",
"err",
"error",
"\n",
"if",
"c",
".",
"ConfigFile",
"!=",
"\"",
"\"",
"{",
"c",
".",
"CFG",
",",
"err",
"=",
"config",
".",
"LoadFile",
"(",
"c",
".",
"ConfigFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintf",
"(",
"os",
".",
"Stderr",
",",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"if",
"err",
":=",
"cmd",
".",
"Main",
"(",
"args",
",",
"c",
")",
";",
"err",
"!=",
"nil",
"{",
"fmt",
".",
"Fprintln",
"(",
"os",
".",
"Stderr",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"return",
"nil",
"\n",
"}"
] | // Start is the entrance point of cfssl command line tools. | [
"Start",
"is",
"the",
"entrance",
"point",
"of",
"cfssl",
"command",
"line",
"tools",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/cli/cli.go#L82-L149 | train |
cloudflare/cfssl | cli/cli.go | ReadStdin | func ReadStdin(filename string) ([]byte, error) {
if filename == "-" {
return ioutil.ReadAll(os.Stdin)
}
return ioutil.ReadFile(filename)
} | go | func ReadStdin(filename string) ([]byte, error) {
if filename == "-" {
return ioutil.ReadAll(os.Stdin)
}
return ioutil.ReadFile(filename)
} | [
"func",
"ReadStdin",
"(",
"filename",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"filename",
"==",
"\"",
"\"",
"{",
"return",
"ioutil",
".",
"ReadAll",
"(",
"os",
".",
"Stdin",
")",
"\n",
"}",
"\n",
"return",
"ioutil",
".",
"ReadFile",
"(",
"filename",
")",
"\n",
"}"
] | // ReadStdin reads from stdin if the file is "-" | [
"ReadStdin",
"reads",
"from",
"stdin",
"if",
"the",
"file",
"is",
"-"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/cli/cli.go#L152-L157 | train |
cloudflare/cfssl | cli/cli.go | PrintCert | func PrintCert(key, csrBytes, cert []byte) {
out := map[string]string{}
if cert != nil {
out["cert"] = string(cert)
}
if key != nil {
out["key"] = string(key)
}
if csrBytes != nil {
out["csr"] = string(csrBytes)
}
jsonOut, err := json.Marshal(out)
if err != nil {
return
}
fmt.Printf("%s\n", jsonOut)
} | go | func PrintCert(key, csrBytes, cert []byte) {
out := map[string]string{}
if cert != nil {
out["cert"] = string(cert)
}
if key != nil {
out["key"] = string(key)
}
if csrBytes != nil {
out["csr"] = string(csrBytes)
}
jsonOut, err := json.Marshal(out)
if err != nil {
return
}
fmt.Printf("%s\n", jsonOut)
} | [
"func",
"PrintCert",
"(",
"key",
",",
"csrBytes",
",",
"cert",
"[",
"]",
"byte",
")",
"{",
"out",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"}",
"\n",
"if",
"cert",
"!=",
"nil",
"{",
"out",
"[",
"\"",
"\"",
"]",
"=",
"string",
"(",
"cert",
")",
"\n",
"}",
"\n\n",
"if",
"key",
"!=",
"nil",
"{",
"out",
"[",
"\"",
"\"",
"]",
"=",
"string",
"(",
"key",
")",
"\n",
"}",
"\n\n",
"if",
"csrBytes",
"!=",
"nil",
"{",
"out",
"[",
"\"",
"\"",
"]",
"=",
"string",
"(",
"csrBytes",
")",
"\n",
"}",
"\n\n",
"jsonOut",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"jsonOut",
")",
"\n",
"}"
] | // PrintCert outputs a cert, key and csr to stdout | [
"PrintCert",
"outputs",
"a",
"cert",
"key",
"and",
"csr",
"to",
"stdout"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/cli/cli.go#L160-L179 | train |
cloudflare/cfssl | cli/cli.go | PrintOCSPResponse | func PrintOCSPResponse(resp []byte) {
b64Resp := base64.StdEncoding.EncodeToString(resp)
out := map[string]string{"ocspResponse": b64Resp}
jsonOut, err := json.Marshal(out)
if err != nil {
return
}
fmt.Printf("%s\n", jsonOut)
} | go | func PrintOCSPResponse(resp []byte) {
b64Resp := base64.StdEncoding.EncodeToString(resp)
out := map[string]string{"ocspResponse": b64Resp}
jsonOut, err := json.Marshal(out)
if err != nil {
return
}
fmt.Printf("%s\n", jsonOut)
} | [
"func",
"PrintOCSPResponse",
"(",
"resp",
"[",
"]",
"byte",
")",
"{",
"b64Resp",
":=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"resp",
")",
"\n\n",
"out",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"b64Resp",
"}",
"\n",
"jsonOut",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"out",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"jsonOut",
")",
"\n",
"}"
] | // PrintOCSPResponse outputs an OCSP response to stdout
// ocspResponse is base64 encoded | [
"PrintOCSPResponse",
"outputs",
"an",
"OCSP",
"response",
"to",
"stdout",
"ocspResponse",
"is",
"base64",
"encoded"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/cli/cli.go#L183-L192 | train |
cloudflare/cfssl | cli/cli.go | PrintCRL | func PrintCRL(certList []byte) {
b64Resp := base64.StdEncoding.EncodeToString(certList)
fmt.Printf("%s\n", b64Resp)
} | go | func PrintCRL(certList []byte) {
b64Resp := base64.StdEncoding.EncodeToString(certList)
fmt.Printf("%s\n", b64Resp)
} | [
"func",
"PrintCRL",
"(",
"certList",
"[",
"]",
"byte",
")",
"{",
"b64Resp",
":=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"certList",
")",
"\n\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\\n",
"\"",
",",
"b64Resp",
")",
"\n",
"}"
] | // PrintCRL outputs the CRL to stdout | [
"PrintCRL",
"outputs",
"the",
"CRL",
"to",
"stdout"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/cli/cli.go#L195-L199 | train |
cloudflare/cfssl | api/health/health.go | NewHealthCheck | func NewHealthCheck() http.Handler {
return api.HTTPHandler{
Handler: api.HandlerFunc(healthHandler),
Methods: []string{"GET"},
}
} | go | func NewHealthCheck() http.Handler {
return api.HTTPHandler{
Handler: api.HandlerFunc(healthHandler),
Methods: []string{"GET"},
}
} | [
"func",
"NewHealthCheck",
"(",
")",
"http",
".",
"Handler",
"{",
"return",
"api",
".",
"HTTPHandler",
"{",
"Handler",
":",
"api",
".",
"HandlerFunc",
"(",
"healthHandler",
")",
",",
"Methods",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
"\n",
"}"
] | // NewHealthCheck creates a new handler to serve health checks. | [
"NewHealthCheck",
"creates",
"a",
"new",
"handler",
"to",
"serve",
"health",
"checks",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/health/health.go#L21-L26 | train |
cloudflare/cfssl | cli/bundle/bundle.go | bundlerMain | func bundlerMain(args []string, c cli.Config) (err error) {
bundler.IntermediateStash = c.IntDir
ubiquity.LoadPlatforms(c.Metadata)
flavor := bundler.BundleFlavor(c.Flavor)
var b *bundler.Bundler
// If it is a force bundle, don't require ca bundle and intermediate bundle
// Otherwise, initialize a bundler with CA bundle and intermediate bundle.
if flavor == bundler.Force {
b = &bundler.Bundler{}
} else {
b, err = bundler.NewBundler(c.CABundleFile, c.IntBundleFile)
if err != nil {
return
}
}
var bundle *bundler.Bundle
if c.CertFile != "" {
if c.CertFile == "-" {
var certPEM, keyPEM []byte
certPEM, err = cli.ReadStdin(c.CertFile)
if err != nil {
return
}
if c.KeyFile != "" {
keyPEM, err = cli.ReadStdin(c.KeyFile)
if err != nil {
return
}
}
bundle, err = b.BundleFromPEMorDER(certPEM, keyPEM, flavor, "")
if err != nil {
return
}
} else {
// Bundle the client cert
bundle, err = b.BundleFromFile(c.CertFile, c.KeyFile, flavor, c.Password)
if err != nil {
return
}
}
} else if c.Domain != "" {
bundle, err = b.BundleFromRemote(c.Domain, c.IP, flavor)
if err != nil {
return
}
} else {
return errors.New("Must specify bundle target through -cert or -domain")
}
marshaled, err := bundle.MarshalJSON()
if err != nil {
return
}
fmt.Printf("%s", marshaled)
return
} | go | func bundlerMain(args []string, c cli.Config) (err error) {
bundler.IntermediateStash = c.IntDir
ubiquity.LoadPlatforms(c.Metadata)
flavor := bundler.BundleFlavor(c.Flavor)
var b *bundler.Bundler
// If it is a force bundle, don't require ca bundle and intermediate bundle
// Otherwise, initialize a bundler with CA bundle and intermediate bundle.
if flavor == bundler.Force {
b = &bundler.Bundler{}
} else {
b, err = bundler.NewBundler(c.CABundleFile, c.IntBundleFile)
if err != nil {
return
}
}
var bundle *bundler.Bundle
if c.CertFile != "" {
if c.CertFile == "-" {
var certPEM, keyPEM []byte
certPEM, err = cli.ReadStdin(c.CertFile)
if err != nil {
return
}
if c.KeyFile != "" {
keyPEM, err = cli.ReadStdin(c.KeyFile)
if err != nil {
return
}
}
bundle, err = b.BundleFromPEMorDER(certPEM, keyPEM, flavor, "")
if err != nil {
return
}
} else {
// Bundle the client cert
bundle, err = b.BundleFromFile(c.CertFile, c.KeyFile, flavor, c.Password)
if err != nil {
return
}
}
} else if c.Domain != "" {
bundle, err = b.BundleFromRemote(c.Domain, c.IP, flavor)
if err != nil {
return
}
} else {
return errors.New("Must specify bundle target through -cert or -domain")
}
marshaled, err := bundle.MarshalJSON()
if err != nil {
return
}
fmt.Printf("%s", marshaled)
return
} | [
"func",
"bundlerMain",
"(",
"args",
"[",
"]",
"string",
",",
"c",
"cli",
".",
"Config",
")",
"(",
"err",
"error",
")",
"{",
"bundler",
".",
"IntermediateStash",
"=",
"c",
".",
"IntDir",
"\n",
"ubiquity",
".",
"LoadPlatforms",
"(",
"c",
".",
"Metadata",
")",
"\n",
"flavor",
":=",
"bundler",
".",
"BundleFlavor",
"(",
"c",
".",
"Flavor",
")",
"\n",
"var",
"b",
"*",
"bundler",
".",
"Bundler",
"\n",
"// If it is a force bundle, don't require ca bundle and intermediate bundle",
"// Otherwise, initialize a bundler with CA bundle and intermediate bundle.",
"if",
"flavor",
"==",
"bundler",
".",
"Force",
"{",
"b",
"=",
"&",
"bundler",
".",
"Bundler",
"{",
"}",
"\n",
"}",
"else",
"{",
"b",
",",
"err",
"=",
"bundler",
".",
"NewBundler",
"(",
"c",
".",
"CABundleFile",
",",
"c",
".",
"IntBundleFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n\n",
"var",
"bundle",
"*",
"bundler",
".",
"Bundle",
"\n",
"if",
"c",
".",
"CertFile",
"!=",
"\"",
"\"",
"{",
"if",
"c",
".",
"CertFile",
"==",
"\"",
"\"",
"{",
"var",
"certPEM",
",",
"keyPEM",
"[",
"]",
"byte",
"\n",
"certPEM",
",",
"err",
"=",
"cli",
".",
"ReadStdin",
"(",
"c",
".",
"CertFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"c",
".",
"KeyFile",
"!=",
"\"",
"\"",
"{",
"keyPEM",
",",
"err",
"=",
"cli",
".",
"ReadStdin",
"(",
"c",
".",
"KeyFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"bundle",
",",
"err",
"=",
"b",
".",
"BundleFromPEMorDER",
"(",
"certPEM",
",",
"keyPEM",
",",
"flavor",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"else",
"{",
"// Bundle the client cert",
"bundle",
",",
"err",
"=",
"b",
".",
"BundleFromFile",
"(",
"c",
".",
"CertFile",
",",
"c",
".",
"KeyFile",
",",
"flavor",
",",
"c",
".",
"Password",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"else",
"if",
"c",
".",
"Domain",
"!=",
"\"",
"\"",
"{",
"bundle",
",",
"err",
"=",
"b",
".",
"BundleFromRemote",
"(",
"c",
".",
"Domain",
",",
"c",
".",
"IP",
",",
"flavor",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"}",
"else",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"marshaled",
",",
"err",
":=",
"bundle",
".",
"MarshalJSON",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"fmt",
".",
"Printf",
"(",
"\"",
"\"",
",",
"marshaled",
")",
"\n",
"return",
"\n",
"}"
] | // bundlerMain is the main CLI of bundler functionality. | [
"bundlerMain",
"is",
"the",
"main",
"CLI",
"of",
"bundler",
"functionality",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/cli/bundle/bundle.go#L29-L85 | train |
cloudflare/cfssl | revoke/revoke.go | ldapURL | func ldapURL(url string) bool {
u, err := neturl.Parse(url)
if err != nil {
log.Warningf("error parsing url %s: %v", url, err)
return false
}
if u.Scheme == "ldap" {
return true
}
return false
} | go | func ldapURL(url string) bool {
u, err := neturl.Parse(url)
if err != nil {
log.Warningf("error parsing url %s: %v", url, err)
return false
}
if u.Scheme == "ldap" {
return true
}
return false
} | [
"func",
"ldapURL",
"(",
"url",
"string",
")",
"bool",
"{",
"u",
",",
"err",
":=",
"neturl",
".",
"Parse",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"url",
",",
"err",
")",
"\n",
"return",
"false",
"\n",
"}",
"\n",
"if",
"u",
".",
"Scheme",
"==",
"\"",
"\"",
"{",
"return",
"true",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // We can't handle LDAP certificates, so this checks to see if the
// URL string points to an LDAP resource so that we can ignore it. | [
"We",
"can",
"t",
"handle",
"LDAP",
"certificates",
"so",
"this",
"checks",
"to",
"see",
"if",
"the",
"URL",
"string",
"points",
"to",
"an",
"LDAP",
"resource",
"so",
"that",
"we",
"can",
"ignore",
"it",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/revoke/revoke.go#L40-L50 | train |
cloudflare/cfssl | revoke/revoke.go | fetchCRL | func fetchCRL(url string) (*pkix.CertificateList, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
} else if resp.StatusCode >= 300 {
return nil, errors.New("failed to retrieve CRL")
}
body, err := crlRead(resp.Body)
if err != nil {
return nil, err
}
resp.Body.Close()
return x509.ParseCRL(body)
} | go | func fetchCRL(url string) (*pkix.CertificateList, error) {
resp, err := http.Get(url)
if err != nil {
return nil, err
} else if resp.StatusCode >= 300 {
return nil, errors.New("failed to retrieve CRL")
}
body, err := crlRead(resp.Body)
if err != nil {
return nil, err
}
resp.Body.Close()
return x509.ParseCRL(body)
} | [
"func",
"fetchCRL",
"(",
"url",
"string",
")",
"(",
"*",
"pkix",
".",
"CertificateList",
",",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"http",
".",
"Get",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"else",
"if",
"resp",
".",
"StatusCode",
">=",
"300",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"body",
",",
"err",
":=",
"crlRead",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"resp",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"return",
"x509",
".",
"ParseCRL",
"(",
"body",
")",
"\n",
"}"
] | // fetchCRL fetches and parses a CRL. | [
"fetchCRL",
"fetches",
"and",
"parses",
"a",
"CRL",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/revoke/revoke.go#L101-L116 | train |
cloudflare/cfssl | revoke/revoke.go | certIsRevokedCRL | func certIsRevokedCRL(cert *x509.Certificate, url string) (revoked, ok bool, err error) {
crl, ok := CRLSet[url]
if ok && crl == nil {
ok = false
crlLock.Lock()
delete(CRLSet, url)
crlLock.Unlock()
}
var shouldFetchCRL = true
if ok {
if !crl.HasExpired(time.Now()) {
shouldFetchCRL = false
}
}
issuer := getIssuer(cert)
if shouldFetchCRL {
var err error
crl, err = fetchCRL(url)
if err != nil {
log.Warningf("failed to fetch CRL: %v", err)
return false, false, err
}
// check CRL signature
if issuer != nil {
err = issuer.CheckCRLSignature(crl)
if err != nil {
log.Warningf("failed to verify CRL: %v", err)
return false, false, err
}
}
crlLock.Lock()
CRLSet[url] = crl
crlLock.Unlock()
}
for _, revoked := range crl.TBSCertList.RevokedCertificates {
if cert.SerialNumber.Cmp(revoked.SerialNumber) == 0 {
log.Info("Serial number match: intermediate is revoked.")
return true, true, err
}
}
return false, true, err
} | go | func certIsRevokedCRL(cert *x509.Certificate, url string) (revoked, ok bool, err error) {
crl, ok := CRLSet[url]
if ok && crl == nil {
ok = false
crlLock.Lock()
delete(CRLSet, url)
crlLock.Unlock()
}
var shouldFetchCRL = true
if ok {
if !crl.HasExpired(time.Now()) {
shouldFetchCRL = false
}
}
issuer := getIssuer(cert)
if shouldFetchCRL {
var err error
crl, err = fetchCRL(url)
if err != nil {
log.Warningf("failed to fetch CRL: %v", err)
return false, false, err
}
// check CRL signature
if issuer != nil {
err = issuer.CheckCRLSignature(crl)
if err != nil {
log.Warningf("failed to verify CRL: %v", err)
return false, false, err
}
}
crlLock.Lock()
CRLSet[url] = crl
crlLock.Unlock()
}
for _, revoked := range crl.TBSCertList.RevokedCertificates {
if cert.SerialNumber.Cmp(revoked.SerialNumber) == 0 {
log.Info("Serial number match: intermediate is revoked.")
return true, true, err
}
}
return false, true, err
} | [
"func",
"certIsRevokedCRL",
"(",
"cert",
"*",
"x509",
".",
"Certificate",
",",
"url",
"string",
")",
"(",
"revoked",
",",
"ok",
"bool",
",",
"err",
"error",
")",
"{",
"crl",
",",
"ok",
":=",
"CRLSet",
"[",
"url",
"]",
"\n",
"if",
"ok",
"&&",
"crl",
"==",
"nil",
"{",
"ok",
"=",
"false",
"\n",
"crlLock",
".",
"Lock",
"(",
")",
"\n",
"delete",
"(",
"CRLSet",
",",
"url",
")",
"\n",
"crlLock",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n\n",
"var",
"shouldFetchCRL",
"=",
"true",
"\n",
"if",
"ok",
"{",
"if",
"!",
"crl",
".",
"HasExpired",
"(",
"time",
".",
"Now",
"(",
")",
")",
"{",
"shouldFetchCRL",
"=",
"false",
"\n",
"}",
"\n",
"}",
"\n\n",
"issuer",
":=",
"getIssuer",
"(",
"cert",
")",
"\n\n",
"if",
"shouldFetchCRL",
"{",
"var",
"err",
"error",
"\n",
"crl",
",",
"err",
"=",
"fetchCRL",
"(",
"url",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
",",
"false",
",",
"err",
"\n",
"}",
"\n\n",
"// check CRL signature",
"if",
"issuer",
"!=",
"nil",
"{",
"err",
"=",
"issuer",
".",
"CheckCRLSignature",
"(",
"crl",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"false",
",",
"false",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"crlLock",
".",
"Lock",
"(",
")",
"\n",
"CRLSet",
"[",
"url",
"]",
"=",
"crl",
"\n",
"crlLock",
".",
"Unlock",
"(",
")",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"revoked",
":=",
"range",
"crl",
".",
"TBSCertList",
".",
"RevokedCertificates",
"{",
"if",
"cert",
".",
"SerialNumber",
".",
"Cmp",
"(",
"revoked",
".",
"SerialNumber",
")",
"==",
"0",
"{",
"log",
".",
"Info",
"(",
"\"",
"\"",
")",
"\n",
"return",
"true",
",",
"true",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"false",
",",
"true",
",",
"err",
"\n",
"}"
] | // check a cert against a specific CRL. Returns the same bool pair
// as revCheck, plus an error if one occurred. | [
"check",
"a",
"cert",
"against",
"a",
"specific",
"CRL",
".",
"Returns",
"the",
"same",
"bool",
"pair",
"as",
"revCheck",
"plus",
"an",
"error",
"if",
"one",
"occurred",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/revoke/revoke.go#L135-L183 | train |
cloudflare/cfssl | revoke/revoke.go | VerifyCertificate | func VerifyCertificate(cert *x509.Certificate) (revoked, ok bool) {
revoked, ok, _ = VerifyCertificateError(cert)
return revoked, ok
} | go | func VerifyCertificate(cert *x509.Certificate) (revoked, ok bool) {
revoked, ok, _ = VerifyCertificateError(cert)
return revoked, ok
} | [
"func",
"VerifyCertificate",
"(",
"cert",
"*",
"x509",
".",
"Certificate",
")",
"(",
"revoked",
",",
"ok",
"bool",
")",
"{",
"revoked",
",",
"ok",
",",
"_",
"=",
"VerifyCertificateError",
"(",
"cert",
")",
"\n",
"return",
"revoked",
",",
"ok",
"\n",
"}"
] | // VerifyCertificate ensures that the certificate passed in hasn't
// expired and checks the CRL for the server. | [
"VerifyCertificate",
"ensures",
"that",
"the",
"certificate",
"passed",
"in",
"hasn",
"t",
"expired",
"and",
"checks",
"the",
"CRL",
"for",
"the",
"server",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/revoke/revoke.go#L187-L190 | train |
cloudflare/cfssl | revoke/revoke.go | VerifyCertificateError | func VerifyCertificateError(cert *x509.Certificate) (revoked, ok bool, err error) {
if !time.Now().Before(cert.NotAfter) {
msg := fmt.Sprintf("Certificate expired %s\n", cert.NotAfter)
log.Info(msg)
return true, true, fmt.Errorf(msg)
} else if !time.Now().After(cert.NotBefore) {
msg := fmt.Sprintf("Certificate isn't valid until %s\n", cert.NotBefore)
log.Info(msg)
return true, true, fmt.Errorf(msg)
}
return revCheck(cert)
} | go | func VerifyCertificateError(cert *x509.Certificate) (revoked, ok bool, err error) {
if !time.Now().Before(cert.NotAfter) {
msg := fmt.Sprintf("Certificate expired %s\n", cert.NotAfter)
log.Info(msg)
return true, true, fmt.Errorf(msg)
} else if !time.Now().After(cert.NotBefore) {
msg := fmt.Sprintf("Certificate isn't valid until %s\n", cert.NotBefore)
log.Info(msg)
return true, true, fmt.Errorf(msg)
}
return revCheck(cert)
} | [
"func",
"VerifyCertificateError",
"(",
"cert",
"*",
"x509",
".",
"Certificate",
")",
"(",
"revoked",
",",
"ok",
"bool",
",",
"err",
"error",
")",
"{",
"if",
"!",
"time",
".",
"Now",
"(",
")",
".",
"Before",
"(",
"cert",
".",
"NotAfter",
")",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"cert",
".",
"NotAfter",
")",
"\n",
"log",
".",
"Info",
"(",
"msg",
")",
"\n",
"return",
"true",
",",
"true",
",",
"fmt",
".",
"Errorf",
"(",
"msg",
")",
"\n",
"}",
"else",
"if",
"!",
"time",
".",
"Now",
"(",
")",
".",
"After",
"(",
"cert",
".",
"NotBefore",
")",
"{",
"msg",
":=",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\\n",
"\"",
",",
"cert",
".",
"NotBefore",
")",
"\n",
"log",
".",
"Info",
"(",
"msg",
")",
"\n",
"return",
"true",
",",
"true",
",",
"fmt",
".",
"Errorf",
"(",
"msg",
")",
"\n",
"}",
"\n",
"return",
"revCheck",
"(",
"cert",
")",
"\n",
"}"
] | // VerifyCertificateError ensures that the certificate passed in hasn't
// expired and checks the CRL for the server. | [
"VerifyCertificateError",
"ensures",
"that",
"the",
"certificate",
"passed",
"in",
"hasn",
"t",
"expired",
"and",
"checks",
"the",
"CRL",
"for",
"the",
"server",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/revoke/revoke.go#L194-L205 | train |
cloudflare/cfssl | certinfo/certinfo.go | ParseCertificate | func ParseCertificate(cert *x509.Certificate) *Certificate {
c := &Certificate{
RawPEM: string(helpers.EncodeCertificatePEM(cert)),
SignatureAlgorithm: helpers.SignatureString(cert.SignatureAlgorithm),
NotBefore: cert.NotBefore,
NotAfter: cert.NotAfter,
Subject: ParseName(cert.Subject),
Issuer: ParseName(cert.Issuer),
SANs: cert.DNSNames,
AKI: formatKeyID(cert.AuthorityKeyId),
SKI: formatKeyID(cert.SubjectKeyId),
SerialNumber: cert.SerialNumber.String(),
}
for _, ip := range cert.IPAddresses {
c.SANs = append(c.SANs, ip.String())
}
return c
} | go | func ParseCertificate(cert *x509.Certificate) *Certificate {
c := &Certificate{
RawPEM: string(helpers.EncodeCertificatePEM(cert)),
SignatureAlgorithm: helpers.SignatureString(cert.SignatureAlgorithm),
NotBefore: cert.NotBefore,
NotAfter: cert.NotAfter,
Subject: ParseName(cert.Subject),
Issuer: ParseName(cert.Issuer),
SANs: cert.DNSNames,
AKI: formatKeyID(cert.AuthorityKeyId),
SKI: formatKeyID(cert.SubjectKeyId),
SerialNumber: cert.SerialNumber.String(),
}
for _, ip := range cert.IPAddresses {
c.SANs = append(c.SANs, ip.String())
}
return c
} | [
"func",
"ParseCertificate",
"(",
"cert",
"*",
"x509",
".",
"Certificate",
")",
"*",
"Certificate",
"{",
"c",
":=",
"&",
"Certificate",
"{",
"RawPEM",
":",
"string",
"(",
"helpers",
".",
"EncodeCertificatePEM",
"(",
"cert",
")",
")",
",",
"SignatureAlgorithm",
":",
"helpers",
".",
"SignatureString",
"(",
"cert",
".",
"SignatureAlgorithm",
")",
",",
"NotBefore",
":",
"cert",
".",
"NotBefore",
",",
"NotAfter",
":",
"cert",
".",
"NotAfter",
",",
"Subject",
":",
"ParseName",
"(",
"cert",
".",
"Subject",
")",
",",
"Issuer",
":",
"ParseName",
"(",
"cert",
".",
"Issuer",
")",
",",
"SANs",
":",
"cert",
".",
"DNSNames",
",",
"AKI",
":",
"formatKeyID",
"(",
"cert",
".",
"AuthorityKeyId",
")",
",",
"SKI",
":",
"formatKeyID",
"(",
"cert",
".",
"SubjectKeyId",
")",
",",
"SerialNumber",
":",
"cert",
".",
"SerialNumber",
".",
"String",
"(",
")",
",",
"}",
"\n",
"for",
"_",
",",
"ip",
":=",
"range",
"cert",
".",
"IPAddresses",
"{",
"c",
".",
"SANs",
"=",
"append",
"(",
"c",
".",
"SANs",
",",
"ip",
".",
"String",
"(",
")",
")",
"\n",
"}",
"\n",
"return",
"c",
"\n",
"}"
] | // ParseCertificate parses an x509 certificate. | [
"ParseCertificate",
"parses",
"an",
"x509",
"certificate",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/certinfo/certinfo.go#L87-L104 | train |
cloudflare/cfssl | certinfo/certinfo.go | ParseCertificateFile | func ParseCertificateFile(certFile string) (*Certificate, error) {
certPEM, err := ioutil.ReadFile(certFile)
if err != nil {
return nil, err
}
return ParseCertificatePEM(certPEM)
} | go | func ParseCertificateFile(certFile string) (*Certificate, error) {
certPEM, err := ioutil.ReadFile(certFile)
if err != nil {
return nil, err
}
return ParseCertificatePEM(certPEM)
} | [
"func",
"ParseCertificateFile",
"(",
"certFile",
"string",
")",
"(",
"*",
"Certificate",
",",
"error",
")",
"{",
"certPEM",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"certFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseCertificatePEM",
"(",
"certPEM",
")",
"\n",
"}"
] | // ParseCertificateFile parses x509 certificate file. | [
"ParseCertificateFile",
"parses",
"x509",
"certificate",
"file",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/certinfo/certinfo.go#L107-L114 | train |
cloudflare/cfssl | certinfo/certinfo.go | ParseCertificatePEM | func ParseCertificatePEM(certPEM []byte) (*Certificate, error) {
cert, err := helpers.ParseCertificatePEM(certPEM)
if err != nil {
return nil, err
}
return ParseCertificate(cert), nil
} | go | func ParseCertificatePEM(certPEM []byte) (*Certificate, error) {
cert, err := helpers.ParseCertificatePEM(certPEM)
if err != nil {
return nil, err
}
return ParseCertificate(cert), nil
} | [
"func",
"ParseCertificatePEM",
"(",
"certPEM",
"[",
"]",
"byte",
")",
"(",
"*",
"Certificate",
",",
"error",
")",
"{",
"cert",
",",
"err",
":=",
"helpers",
".",
"ParseCertificatePEM",
"(",
"certPEM",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseCertificate",
"(",
"cert",
")",
",",
"nil",
"\n",
"}"
] | // ParseCertificatePEM parses an x509 certificate PEM. | [
"ParseCertificatePEM",
"parses",
"an",
"x509",
"certificate",
"PEM",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/certinfo/certinfo.go#L117-L124 | train |
cloudflare/cfssl | certinfo/certinfo.go | ParseCSRPEM | func ParseCSRPEM(csrPEM []byte) (*x509.CertificateRequest, error) {
csrObject, err := helpers.ParseCSRPEM(csrPEM)
if err != nil {
return nil, err
}
return csrObject, nil
} | go | func ParseCSRPEM(csrPEM []byte) (*x509.CertificateRequest, error) {
csrObject, err := helpers.ParseCSRPEM(csrPEM)
if err != nil {
return nil, err
}
return csrObject, nil
} | [
"func",
"ParseCSRPEM",
"(",
"csrPEM",
"[",
"]",
"byte",
")",
"(",
"*",
"x509",
".",
"CertificateRequest",
",",
"error",
")",
"{",
"csrObject",
",",
"err",
":=",
"helpers",
".",
"ParseCSRPEM",
"(",
"csrPEM",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"csrObject",
",",
"nil",
"\n",
"}"
] | // ParseCSRPEM uses the helper to parse an x509 CSR PEM. | [
"ParseCSRPEM",
"uses",
"the",
"helper",
"to",
"parse",
"an",
"x509",
"CSR",
"PEM",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/certinfo/certinfo.go#L127-L134 | train |
cloudflare/cfssl | certinfo/certinfo.go | ParseCSRFile | func ParseCSRFile(csrFile string) (*x509.CertificateRequest, error) {
csrPEM, err := ioutil.ReadFile(csrFile)
if err != nil {
return nil, err
}
return ParseCSRPEM(csrPEM)
} | go | func ParseCSRFile(csrFile string) (*x509.CertificateRequest, error) {
csrPEM, err := ioutil.ReadFile(csrFile)
if err != nil {
return nil, err
}
return ParseCSRPEM(csrPEM)
} | [
"func",
"ParseCSRFile",
"(",
"csrFile",
"string",
")",
"(",
"*",
"x509",
".",
"CertificateRequest",
",",
"error",
")",
"{",
"csrPEM",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"csrFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"ParseCSRPEM",
"(",
"csrPEM",
")",
"\n",
"}"
] | // ParseCSRFile uses the helper to parse an x509 CSR PEM file. | [
"ParseCSRFile",
"uses",
"the",
"helper",
"to",
"parse",
"an",
"x509",
"CSR",
"PEM",
"file",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/certinfo/certinfo.go#L137-L144 | train |
cloudflare/cfssl | certinfo/certinfo.go | ParseCertificateDomain | func ParseCertificateDomain(domain string) (cert *Certificate, err error) {
var host, port string
if host, port, err = net.SplitHostPort(domain); err != nil {
host = domain
port = "443"
}
var conn *tls.Conn
conn, err = tls.DialWithDialer(&net.Dialer{Timeout: 10 * time.Second}, "tcp", net.JoinHostPort(host, port), &tls.Config{InsecureSkipVerify: true})
if err != nil {
return
}
defer conn.Close()
if len(conn.ConnectionState().PeerCertificates) == 0 {
return nil, errors.New("received no server certificates")
}
cert = ParseCertificate(conn.ConnectionState().PeerCertificates[0])
return
} | go | func ParseCertificateDomain(domain string) (cert *Certificate, err error) {
var host, port string
if host, port, err = net.SplitHostPort(domain); err != nil {
host = domain
port = "443"
}
var conn *tls.Conn
conn, err = tls.DialWithDialer(&net.Dialer{Timeout: 10 * time.Second}, "tcp", net.JoinHostPort(host, port), &tls.Config{InsecureSkipVerify: true})
if err != nil {
return
}
defer conn.Close()
if len(conn.ConnectionState().PeerCertificates) == 0 {
return nil, errors.New("received no server certificates")
}
cert = ParseCertificate(conn.ConnectionState().PeerCertificates[0])
return
} | [
"func",
"ParseCertificateDomain",
"(",
"domain",
"string",
")",
"(",
"cert",
"*",
"Certificate",
",",
"err",
"error",
")",
"{",
"var",
"host",
",",
"port",
"string",
"\n",
"if",
"host",
",",
"port",
",",
"err",
"=",
"net",
".",
"SplitHostPort",
"(",
"domain",
")",
";",
"err",
"!=",
"nil",
"{",
"host",
"=",
"domain",
"\n",
"port",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"var",
"conn",
"*",
"tls",
".",
"Conn",
"\n",
"conn",
",",
"err",
"=",
"tls",
".",
"DialWithDialer",
"(",
"&",
"net",
".",
"Dialer",
"{",
"Timeout",
":",
"10",
"*",
"time",
".",
"Second",
"}",
",",
"\"",
"\"",
",",
"net",
".",
"JoinHostPort",
"(",
"host",
",",
"port",
")",
",",
"&",
"tls",
".",
"Config",
"{",
"InsecureSkipVerify",
":",
"true",
"}",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"conn",
".",
"Close",
"(",
")",
"\n\n",
"if",
"len",
"(",
"conn",
".",
"ConnectionState",
"(",
")",
".",
"PeerCertificates",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"cert",
"=",
"ParseCertificate",
"(",
"conn",
".",
"ConnectionState",
"(",
")",
".",
"PeerCertificates",
"[",
"0",
"]",
")",
"\n",
"return",
"\n",
"}"
] | // ParseCertificateDomain parses the certificate served by the given domain. | [
"ParseCertificateDomain",
"parses",
"the",
"certificate",
"served",
"by",
"the",
"given",
"domain",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/certinfo/certinfo.go#L147-L167 | train |
cloudflare/cfssl | certinfo/certinfo.go | ParseSerialNumber | func ParseSerialNumber(serial, aki string, dbAccessor certdb.Accessor) (*Certificate, error) {
normalizedAKI := strings.ToLower(aki)
normalizedAKI = strings.Replace(normalizedAKI, ":", "", -1)
certificates, err := dbAccessor.GetCertificate(serial, normalizedAKI)
if err != nil {
return nil, err
}
if len(certificates) < 1 {
return nil, errors.New("no certificate found")
}
if len(certificates) > 1 {
return nil, errors.New("more than one certificate found")
}
return ParseCertificatePEM([]byte(certificates[0].PEM))
} | go | func ParseSerialNumber(serial, aki string, dbAccessor certdb.Accessor) (*Certificate, error) {
normalizedAKI := strings.ToLower(aki)
normalizedAKI = strings.Replace(normalizedAKI, ":", "", -1)
certificates, err := dbAccessor.GetCertificate(serial, normalizedAKI)
if err != nil {
return nil, err
}
if len(certificates) < 1 {
return nil, errors.New("no certificate found")
}
if len(certificates) > 1 {
return nil, errors.New("more than one certificate found")
}
return ParseCertificatePEM([]byte(certificates[0].PEM))
} | [
"func",
"ParseSerialNumber",
"(",
"serial",
",",
"aki",
"string",
",",
"dbAccessor",
"certdb",
".",
"Accessor",
")",
"(",
"*",
"Certificate",
",",
"error",
")",
"{",
"normalizedAKI",
":=",
"strings",
".",
"ToLower",
"(",
"aki",
")",
"\n",
"normalizedAKI",
"=",
"strings",
".",
"Replace",
"(",
"normalizedAKI",
",",
"\"",
"\"",
",",
"\"",
"\"",
",",
"-",
"1",
")",
"\n\n",
"certificates",
",",
"err",
":=",
"dbAccessor",
".",
"GetCertificate",
"(",
"serial",
",",
"normalizedAKI",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"certificates",
")",
"<",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"certificates",
")",
">",
"1",
"{",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"return",
"ParseCertificatePEM",
"(",
"[",
"]",
"byte",
"(",
"certificates",
"[",
"0",
"]",
".",
"PEM",
")",
")",
"\n",
"}"
] | // ParseSerialNumber parses the serial number and does a lookup in the data
// storage used for certificates. The authority key is required for the lookup
// to work and must be passed as a hex string. | [
"ParseSerialNumber",
"parses",
"the",
"serial",
"number",
"and",
"does",
"a",
"lookup",
"in",
"the",
"data",
"storage",
"used",
"for",
"certificates",
".",
"The",
"authority",
"key",
"is",
"required",
"for",
"the",
"lookup",
"to",
"work",
"and",
"must",
"be",
"passed",
"as",
"a",
"hex",
"string",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/certinfo/certinfo.go#L172-L190 | train |
cloudflare/cfssl | api/info/info.go | NewHandler | func NewHandler(s signer.Signer) (http.Handler, error) {
return &api.HTTPHandler{
Handler: &Handler{
sign: s,
},
Methods: []string{"POST"},
}, nil
} | go | func NewHandler(s signer.Signer) (http.Handler, error) {
return &api.HTTPHandler{
Handler: &Handler{
sign: s,
},
Methods: []string{"POST"},
}, nil
} | [
"func",
"NewHandler",
"(",
"s",
"signer",
".",
"Signer",
")",
"(",
"http",
".",
"Handler",
",",
"error",
")",
"{",
"return",
"&",
"api",
".",
"HTTPHandler",
"{",
"Handler",
":",
"&",
"Handler",
"{",
"sign",
":",
"s",
",",
"}",
",",
"Methods",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewHandler creates a new handler to serve information on the CA's
// certificates, taking a signer to use. | [
"NewHandler",
"creates",
"a",
"new",
"handler",
"to",
"serve",
"information",
"on",
"the",
"CA",
"s",
"certificates",
"taking",
"a",
"signer",
"to",
"use",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/info/info.go#L24-L31 | train |
cloudflare/cfssl | api/info/info.go | Handle | func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) error {
req := new(info.Req)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Warningf("failed to read request body: %v", err)
return errors.NewBadRequest(err)
}
r.Body.Close()
err = json.Unmarshal(body, req)
if err != nil {
log.Warningf("failed to unmarshal request: %v", err)
return errors.NewBadRequest(err)
}
resp, err := h.sign.Info(*req)
if err != nil {
return err
}
response := api.NewSuccessResponse(resp)
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
return enc.Encode(response)
} | go | func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) error {
req := new(info.Req)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Warningf("failed to read request body: %v", err)
return errors.NewBadRequest(err)
}
r.Body.Close()
err = json.Unmarshal(body, req)
if err != nil {
log.Warningf("failed to unmarshal request: %v", err)
return errors.NewBadRequest(err)
}
resp, err := h.sign.Info(*req)
if err != nil {
return err
}
response := api.NewSuccessResponse(resp)
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
return enc.Encode(response)
} | [
"func",
"(",
"h",
"*",
"Handler",
")",
"Handle",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"req",
":=",
"new",
"(",
"info",
".",
"Req",
")",
"\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"NewBadRequest",
"(",
"err",
")",
"\n",
"}",
"\n",
"r",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"NewBadRequest",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"h",
".",
"sign",
".",
"Info",
"(",
"*",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"response",
":=",
"api",
".",
"NewSuccessResponse",
"(",
"resp",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"return",
"enc",
".",
"Encode",
"(",
"response",
")",
"\n",
"}"
] | // Handle listens for incoming requests for CA information, and returns
// a list containing information on each root certificate. | [
"Handle",
"listens",
"for",
"incoming",
"requests",
"for",
"CA",
"information",
"and",
"returns",
"a",
"list",
"containing",
"information",
"on",
"each",
"root",
"certificate",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/info/info.go#L35-L59 | train |
cloudflare/cfssl | api/info/info.go | NewMultiHandler | func NewMultiHandler(signers map[string]signer.Signer, defaultLabel string) (http.Handler, error) {
return &api.HTTPHandler{
Handler: &MultiHandler{
signers: signers,
defaultLabel: defaultLabel,
},
Methods: []string{"POST"},
}, nil
} | go | func NewMultiHandler(signers map[string]signer.Signer, defaultLabel string) (http.Handler, error) {
return &api.HTTPHandler{
Handler: &MultiHandler{
signers: signers,
defaultLabel: defaultLabel,
},
Methods: []string{"POST"},
}, nil
} | [
"func",
"NewMultiHandler",
"(",
"signers",
"map",
"[",
"string",
"]",
"signer",
".",
"Signer",
",",
"defaultLabel",
"string",
")",
"(",
"http",
".",
"Handler",
",",
"error",
")",
"{",
"return",
"&",
"api",
".",
"HTTPHandler",
"{",
"Handler",
":",
"&",
"MultiHandler",
"{",
"signers",
":",
"signers",
",",
"defaultLabel",
":",
"defaultLabel",
",",
"}",
",",
"Methods",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewMultiHandler constructs a MultiHandler from a mapping of labels
// to signers and the default label. | [
"NewMultiHandler",
"constructs",
"a",
"MultiHandler",
"from",
"a",
"mapping",
"of",
"labels",
"to",
"signers",
"and",
"the",
"default",
"label",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/info/info.go#L72-L80 | train |
cloudflare/cfssl | api/info/info.go | Handle | func (h *MultiHandler) Handle(w http.ResponseWriter, r *http.Request) error {
req := new(info.Req)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Warningf("failed to read request body: %v", err)
return errors.NewBadRequest(err)
}
r.Body.Close()
err = json.Unmarshal(body, req)
if err != nil {
log.Warningf("failed to unmarshal request: %v", err)
return errors.NewBadRequest(err)
}
log.Debug("checking label")
if req.Label == "" {
req.Label = h.defaultLabel
}
if _, ok := h.signers[req.Label]; !ok {
log.Warningf("request for invalid endpoint")
return errors.NewBadRequestString("bad label")
}
log.Debug("getting info")
resp, err := h.signers[req.Label].Info(*req)
if err != nil {
log.Infof("error getting certificate: %v", err)
return err
}
response := api.NewSuccessResponse(resp)
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
return enc.Encode(response)
} | go | func (h *MultiHandler) Handle(w http.ResponseWriter, r *http.Request) error {
req := new(info.Req)
body, err := ioutil.ReadAll(r.Body)
if err != nil {
log.Warningf("failed to read request body: %v", err)
return errors.NewBadRequest(err)
}
r.Body.Close()
err = json.Unmarshal(body, req)
if err != nil {
log.Warningf("failed to unmarshal request: %v", err)
return errors.NewBadRequest(err)
}
log.Debug("checking label")
if req.Label == "" {
req.Label = h.defaultLabel
}
if _, ok := h.signers[req.Label]; !ok {
log.Warningf("request for invalid endpoint")
return errors.NewBadRequestString("bad label")
}
log.Debug("getting info")
resp, err := h.signers[req.Label].Info(*req)
if err != nil {
log.Infof("error getting certificate: %v", err)
return err
}
response := api.NewSuccessResponse(resp)
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
return enc.Encode(response)
} | [
"func",
"(",
"h",
"*",
"MultiHandler",
")",
"Handle",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"req",
":=",
"new",
"(",
"info",
".",
"Req",
")",
"\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"NewBadRequest",
"(",
"err",
")",
"\n",
"}",
"\n",
"r",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"NewBadRequest",
"(",
"err",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"if",
"req",
".",
"Label",
"==",
"\"",
"\"",
"{",
"req",
".",
"Label",
"=",
"h",
".",
"defaultLabel",
"\n",
"}",
"\n\n",
"if",
"_",
",",
"ok",
":=",
"h",
".",
"signers",
"[",
"req",
".",
"Label",
"]",
";",
"!",
"ok",
"{",
"log",
".",
"Warningf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"errors",
".",
"NewBadRequestString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
")",
"\n",
"resp",
",",
"err",
":=",
"h",
".",
"signers",
"[",
"req",
".",
"Label",
"]",
".",
"Info",
"(",
"*",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"err",
"\n",
"}",
"\n\n",
"response",
":=",
"api",
".",
"NewSuccessResponse",
"(",
"resp",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"return",
"enc",
".",
"Encode",
"(",
"response",
")",
"\n",
"}"
] | // Handle accepts client information requests, and uses the label to
// look up the signer whose public certificate should be retrieved. If
// the label is empty, the default label is used. | [
"Handle",
"accepts",
"client",
"information",
"requests",
"and",
"uses",
"the",
"label",
"to",
"look",
"up",
"the",
"signer",
"whose",
"public",
"certificate",
"should",
"be",
"retrieved",
".",
"If",
"the",
"label",
"is",
"empty",
"the",
"default",
"label",
"is",
"used",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/info/info.go#L85-L121 | train |
cloudflare/cfssl | ocsp/ocsp.go | ReasonStringToCode | func ReasonStringToCode(reason string) (reasonCode int, err error) {
// default to 0
if reason == "" {
return 0, nil
}
reasonCode, present := revocationReasonCodes[strings.ToLower(reason)]
if !present {
reasonCode, err = strconv.Atoi(reason)
if err != nil {
return
}
if reasonCode >= ocsp.AACompromise || reasonCode <= ocsp.Unspecified {
return 0, cferr.New(cferr.OCSPError, cferr.InvalidStatus)
}
}
return
} | go | func ReasonStringToCode(reason string) (reasonCode int, err error) {
// default to 0
if reason == "" {
return 0, nil
}
reasonCode, present := revocationReasonCodes[strings.ToLower(reason)]
if !present {
reasonCode, err = strconv.Atoi(reason)
if err != nil {
return
}
if reasonCode >= ocsp.AACompromise || reasonCode <= ocsp.Unspecified {
return 0, cferr.New(cferr.OCSPError, cferr.InvalidStatus)
}
}
return
} | [
"func",
"ReasonStringToCode",
"(",
"reason",
"string",
")",
"(",
"reasonCode",
"int",
",",
"err",
"error",
")",
"{",
"// default to 0",
"if",
"reason",
"==",
"\"",
"\"",
"{",
"return",
"0",
",",
"nil",
"\n",
"}",
"\n\n",
"reasonCode",
",",
"present",
":=",
"revocationReasonCodes",
"[",
"strings",
".",
"ToLower",
"(",
"reason",
")",
"]",
"\n",
"if",
"!",
"present",
"{",
"reasonCode",
",",
"err",
"=",
"strconv",
".",
"Atoi",
"(",
"reason",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"reasonCode",
">=",
"ocsp",
".",
"AACompromise",
"||",
"reasonCode",
"<=",
"ocsp",
".",
"Unspecified",
"{",
"return",
"0",
",",
"cferr",
".",
"New",
"(",
"cferr",
".",
"OCSPError",
",",
"cferr",
".",
"InvalidStatus",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // ReasonStringToCode tries to convert a reason string to an integer code | [
"ReasonStringToCode",
"tries",
"to",
"convert",
"a",
"reason",
"string",
"to",
"an",
"integer",
"code"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/ocsp/ocsp.go#L87-L105 | train |
cloudflare/cfssl | ocsp/ocsp.go | NewSignerFromFile | func NewSignerFromFile(issuerFile, responderFile, keyFile string, interval time.Duration) (Signer, error) {
log.Debug("Loading issuer cert: ", issuerFile)
issuerBytes, err := helpers.ReadBytes(issuerFile)
if err != nil {
return nil, err
}
log.Debug("Loading responder cert: ", responderFile)
responderBytes, err := ioutil.ReadFile(responderFile)
if err != nil {
return nil, err
}
log.Debug("Loading responder key: ", keyFile)
keyBytes, err := ioutil.ReadFile(keyFile)
if err != nil {
return nil, cferr.Wrap(cferr.CertificateError, cferr.ReadFailed, err)
}
issuerCert, err := helpers.ParseCertificatePEM(issuerBytes)
if err != nil {
return nil, err
}
responderCert, err := helpers.ParseCertificatePEM(responderBytes)
if err != nil {
return nil, err
}
key, err := helpers.ParsePrivateKeyPEM(keyBytes)
if err != nil {
log.Debug("Malformed private key %v", err)
return nil, err
}
return NewSigner(issuerCert, responderCert, key, interval)
} | go | func NewSignerFromFile(issuerFile, responderFile, keyFile string, interval time.Duration) (Signer, error) {
log.Debug("Loading issuer cert: ", issuerFile)
issuerBytes, err := helpers.ReadBytes(issuerFile)
if err != nil {
return nil, err
}
log.Debug("Loading responder cert: ", responderFile)
responderBytes, err := ioutil.ReadFile(responderFile)
if err != nil {
return nil, err
}
log.Debug("Loading responder key: ", keyFile)
keyBytes, err := ioutil.ReadFile(keyFile)
if err != nil {
return nil, cferr.Wrap(cferr.CertificateError, cferr.ReadFailed, err)
}
issuerCert, err := helpers.ParseCertificatePEM(issuerBytes)
if err != nil {
return nil, err
}
responderCert, err := helpers.ParseCertificatePEM(responderBytes)
if err != nil {
return nil, err
}
key, err := helpers.ParsePrivateKeyPEM(keyBytes)
if err != nil {
log.Debug("Malformed private key %v", err)
return nil, err
}
return NewSigner(issuerCert, responderCert, key, interval)
} | [
"func",
"NewSignerFromFile",
"(",
"issuerFile",
",",
"responderFile",
",",
"keyFile",
"string",
",",
"interval",
"time",
".",
"Duration",
")",
"(",
"Signer",
",",
"error",
")",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"issuerFile",
")",
"\n",
"issuerBytes",
",",
"err",
":=",
"helpers",
".",
"ReadBytes",
"(",
"issuerFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"responderFile",
")",
"\n",
"responderBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"responderFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"keyFile",
")",
"\n",
"keyBytes",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"keyFile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"cferr",
".",
"Wrap",
"(",
"cferr",
".",
"CertificateError",
",",
"cferr",
".",
"ReadFailed",
",",
"err",
")",
"\n",
"}",
"\n\n",
"issuerCert",
",",
"err",
":=",
"helpers",
".",
"ParseCertificatePEM",
"(",
"issuerBytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"responderCert",
",",
"err",
":=",
"helpers",
".",
"ParseCertificatePEM",
"(",
"responderBytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"key",
",",
"err",
":=",
"helpers",
".",
"ParsePrivateKeyPEM",
"(",
"keyBytes",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"NewSigner",
"(",
"issuerCert",
",",
"responderCert",
",",
"key",
",",
"interval",
")",
"\n",
"}"
] | // NewSignerFromFile reads the issuer cert, the responder cert and the responder key
// from PEM files, and takes an interval in seconds | [
"NewSignerFromFile",
"reads",
"the",
"issuer",
"cert",
"the",
"responder",
"cert",
"and",
"the",
"responder",
"key",
"from",
"PEM",
"files",
"and",
"takes",
"an",
"interval",
"in",
"seconds"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/ocsp/ocsp.go#L109-L143 | train |
cloudflare/cfssl | ocsp/ocsp.go | NewSigner | func NewSigner(issuer, responder *x509.Certificate, key crypto.Signer, interval time.Duration) (Signer, error) {
return &StandardSigner{
issuer: issuer,
responder: responder,
key: key,
interval: interval,
}, nil
} | go | func NewSigner(issuer, responder *x509.Certificate, key crypto.Signer, interval time.Duration) (Signer, error) {
return &StandardSigner{
issuer: issuer,
responder: responder,
key: key,
interval: interval,
}, nil
} | [
"func",
"NewSigner",
"(",
"issuer",
",",
"responder",
"*",
"x509",
".",
"Certificate",
",",
"key",
"crypto",
".",
"Signer",
",",
"interval",
"time",
".",
"Duration",
")",
"(",
"Signer",
",",
"error",
")",
"{",
"return",
"&",
"StandardSigner",
"{",
"issuer",
":",
"issuer",
",",
"responder",
":",
"responder",
",",
"key",
":",
"key",
",",
"interval",
":",
"interval",
",",
"}",
",",
"nil",
"\n",
"}"
] | // NewSigner simply constructs a new StandardSigner object from the inputs,
// taking the interval in seconds | [
"NewSigner",
"simply",
"constructs",
"a",
"new",
"StandardSigner",
"object",
"from",
"the",
"inputs",
"taking",
"the",
"interval",
"in",
"seconds"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/ocsp/ocsp.go#L147-L154 | train |
cloudflare/cfssl | ocsp/ocsp.go | Sign | func (s StandardSigner) Sign(req SignRequest) ([]byte, error) {
if req.Certificate == nil {
return nil, cferr.New(cferr.OCSPError, cferr.ReadFailed)
}
// Verify that req.Certificate is issued under s.issuer
if bytes.Compare(req.Certificate.RawIssuer, s.issuer.RawSubject) != 0 {
return nil, cferr.New(cferr.OCSPError, cferr.IssuerMismatch)
}
err := req.Certificate.CheckSignatureFrom(s.issuer)
if err != nil {
return nil, cferr.Wrap(cferr.OCSPError, cferr.VerifyFailed, err)
}
var thisUpdate, nextUpdate time.Time
if req.ThisUpdate != nil {
thisUpdate = *req.ThisUpdate
} else {
// Round thisUpdate times down to the nearest hour
thisUpdate = time.Now().Truncate(time.Hour)
}
if req.NextUpdate != nil {
nextUpdate = *req.NextUpdate
} else {
nextUpdate = thisUpdate.Add(s.interval)
}
status, ok := StatusCode[req.Status]
if !ok {
return nil, cferr.New(cferr.OCSPError, cferr.InvalidStatus)
}
// If the OCSP responder is the same as the issuer, there is no need to
// include any certificate in the OCSP response, which decreases the byte size
// of OCSP responses dramatically.
certificate := s.responder
if s.issuer == s.responder || bytes.Equal(s.issuer.Raw, s.responder.Raw) {
certificate = nil
}
template := ocsp.Response{
Status: status,
SerialNumber: req.Certificate.SerialNumber,
ThisUpdate: thisUpdate,
NextUpdate: nextUpdate,
Certificate: certificate,
ExtraExtensions: req.Extensions,
IssuerHash: req.IssuerHash,
}
if status == ocsp.Revoked {
template.RevokedAt = req.RevokedAt
template.RevocationReason = req.Reason
}
return ocsp.CreateResponse(s.issuer, s.responder, template, s.key)
} | go | func (s StandardSigner) Sign(req SignRequest) ([]byte, error) {
if req.Certificate == nil {
return nil, cferr.New(cferr.OCSPError, cferr.ReadFailed)
}
// Verify that req.Certificate is issued under s.issuer
if bytes.Compare(req.Certificate.RawIssuer, s.issuer.RawSubject) != 0 {
return nil, cferr.New(cferr.OCSPError, cferr.IssuerMismatch)
}
err := req.Certificate.CheckSignatureFrom(s.issuer)
if err != nil {
return nil, cferr.Wrap(cferr.OCSPError, cferr.VerifyFailed, err)
}
var thisUpdate, nextUpdate time.Time
if req.ThisUpdate != nil {
thisUpdate = *req.ThisUpdate
} else {
// Round thisUpdate times down to the nearest hour
thisUpdate = time.Now().Truncate(time.Hour)
}
if req.NextUpdate != nil {
nextUpdate = *req.NextUpdate
} else {
nextUpdate = thisUpdate.Add(s.interval)
}
status, ok := StatusCode[req.Status]
if !ok {
return nil, cferr.New(cferr.OCSPError, cferr.InvalidStatus)
}
// If the OCSP responder is the same as the issuer, there is no need to
// include any certificate in the OCSP response, which decreases the byte size
// of OCSP responses dramatically.
certificate := s.responder
if s.issuer == s.responder || bytes.Equal(s.issuer.Raw, s.responder.Raw) {
certificate = nil
}
template := ocsp.Response{
Status: status,
SerialNumber: req.Certificate.SerialNumber,
ThisUpdate: thisUpdate,
NextUpdate: nextUpdate,
Certificate: certificate,
ExtraExtensions: req.Extensions,
IssuerHash: req.IssuerHash,
}
if status == ocsp.Revoked {
template.RevokedAt = req.RevokedAt
template.RevocationReason = req.Reason
}
return ocsp.CreateResponse(s.issuer, s.responder, template, s.key)
} | [
"func",
"(",
"s",
"StandardSigner",
")",
"Sign",
"(",
"req",
"SignRequest",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"if",
"req",
".",
"Certificate",
"==",
"nil",
"{",
"return",
"nil",
",",
"cferr",
".",
"New",
"(",
"cferr",
".",
"OCSPError",
",",
"cferr",
".",
"ReadFailed",
")",
"\n",
"}",
"\n\n",
"// Verify that req.Certificate is issued under s.issuer",
"if",
"bytes",
".",
"Compare",
"(",
"req",
".",
"Certificate",
".",
"RawIssuer",
",",
"s",
".",
"issuer",
".",
"RawSubject",
")",
"!=",
"0",
"{",
"return",
"nil",
",",
"cferr",
".",
"New",
"(",
"cferr",
".",
"OCSPError",
",",
"cferr",
".",
"IssuerMismatch",
")",
"\n",
"}",
"\n\n",
"err",
":=",
"req",
".",
"Certificate",
".",
"CheckSignatureFrom",
"(",
"s",
".",
"issuer",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"cferr",
".",
"Wrap",
"(",
"cferr",
".",
"OCSPError",
",",
"cferr",
".",
"VerifyFailed",
",",
"err",
")",
"\n",
"}",
"\n\n",
"var",
"thisUpdate",
",",
"nextUpdate",
"time",
".",
"Time",
"\n",
"if",
"req",
".",
"ThisUpdate",
"!=",
"nil",
"{",
"thisUpdate",
"=",
"*",
"req",
".",
"ThisUpdate",
"\n",
"}",
"else",
"{",
"// Round thisUpdate times down to the nearest hour",
"thisUpdate",
"=",
"time",
".",
"Now",
"(",
")",
".",
"Truncate",
"(",
"time",
".",
"Hour",
")",
"\n",
"}",
"\n",
"if",
"req",
".",
"NextUpdate",
"!=",
"nil",
"{",
"nextUpdate",
"=",
"*",
"req",
".",
"NextUpdate",
"\n",
"}",
"else",
"{",
"nextUpdate",
"=",
"thisUpdate",
".",
"Add",
"(",
"s",
".",
"interval",
")",
"\n",
"}",
"\n\n",
"status",
",",
"ok",
":=",
"StatusCode",
"[",
"req",
".",
"Status",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"cferr",
".",
"New",
"(",
"cferr",
".",
"OCSPError",
",",
"cferr",
".",
"InvalidStatus",
")",
"\n",
"}",
"\n\n",
"// If the OCSP responder is the same as the issuer, there is no need to",
"// include any certificate in the OCSP response, which decreases the byte size",
"// of OCSP responses dramatically.",
"certificate",
":=",
"s",
".",
"responder",
"\n",
"if",
"s",
".",
"issuer",
"==",
"s",
".",
"responder",
"||",
"bytes",
".",
"Equal",
"(",
"s",
".",
"issuer",
".",
"Raw",
",",
"s",
".",
"responder",
".",
"Raw",
")",
"{",
"certificate",
"=",
"nil",
"\n",
"}",
"\n\n",
"template",
":=",
"ocsp",
".",
"Response",
"{",
"Status",
":",
"status",
",",
"SerialNumber",
":",
"req",
".",
"Certificate",
".",
"SerialNumber",
",",
"ThisUpdate",
":",
"thisUpdate",
",",
"NextUpdate",
":",
"nextUpdate",
",",
"Certificate",
":",
"certificate",
",",
"ExtraExtensions",
":",
"req",
".",
"Extensions",
",",
"IssuerHash",
":",
"req",
".",
"IssuerHash",
",",
"}",
"\n\n",
"if",
"status",
"==",
"ocsp",
".",
"Revoked",
"{",
"template",
".",
"RevokedAt",
"=",
"req",
".",
"RevokedAt",
"\n",
"template",
".",
"RevocationReason",
"=",
"req",
".",
"Reason",
"\n",
"}",
"\n\n",
"return",
"ocsp",
".",
"CreateResponse",
"(",
"s",
".",
"issuer",
",",
"s",
".",
"responder",
",",
"template",
",",
"s",
".",
"key",
")",
"\n",
"}"
] | // Sign is used with an OCSP signer to request the issuance of
// an OCSP response. | [
"Sign",
"is",
"used",
"with",
"an",
"OCSP",
"signer",
"to",
"request",
"the",
"issuance",
"of",
"an",
"OCSP",
"response",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/ocsp/ocsp.go#L158-L215 | train |
cloudflare/cfssl | errors/error.go | Error | func (e *Error) Error() string {
marshaled, err := json.Marshal(e)
if err != nil {
panic(err)
}
return string(marshaled)
} | go | func (e *Error) Error() string {
marshaled, err := json.Marshal(e)
if err != nil {
panic(err)
}
return string(marshaled)
} | [
"func",
"(",
"e",
"*",
"Error",
")",
"Error",
"(",
")",
"string",
"{",
"marshaled",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"e",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"panic",
"(",
"err",
")",
"\n",
"}",
"\n",
"return",
"string",
"(",
"marshaled",
")",
"\n\n",
"}"
] | // The error interface implementation, which formats to a JSON object string. | [
"The",
"error",
"interface",
"implementation",
"which",
"formats",
"to",
"a",
"JSON",
"object",
"string",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/errors/error.go#L216-L223 | train |
cloudflare/cfssl | errors/error.go | Wrap | func Wrap(category Category, reason Reason, err error) *Error {
errorCode := int(category) + int(reason)
if err == nil {
panic("Wrap needs a supplied error to initialize.")
}
// do not double wrap a error
switch err.(type) {
case *Error:
panic("Unable to wrap a wrapped error.")
}
switch category {
case CertificateError:
// given VerifyFailed , report the status with more detailed status code
// for some certificate errors we care.
if reason == VerifyFailed {
switch errorType := err.(type) {
case x509.CertificateInvalidError:
errorCode += certificateInvalid + int(errorType.Reason)
case x509.UnknownAuthorityError:
errorCode += unknownAuthority
}
}
case PrivateKeyError, IntermediatesError, RootError, PolicyError, DialError,
APIClientError, CSRError, CTError, CertStoreError, OCSPError:
// no-op, just use the error
default:
panic(fmt.Sprintf("Unsupported CFSSL error type: %d.",
category))
}
return &Error{ErrorCode: errorCode, Message: err.Error()}
} | go | func Wrap(category Category, reason Reason, err error) *Error {
errorCode := int(category) + int(reason)
if err == nil {
panic("Wrap needs a supplied error to initialize.")
}
// do not double wrap a error
switch err.(type) {
case *Error:
panic("Unable to wrap a wrapped error.")
}
switch category {
case CertificateError:
// given VerifyFailed , report the status with more detailed status code
// for some certificate errors we care.
if reason == VerifyFailed {
switch errorType := err.(type) {
case x509.CertificateInvalidError:
errorCode += certificateInvalid + int(errorType.Reason)
case x509.UnknownAuthorityError:
errorCode += unknownAuthority
}
}
case PrivateKeyError, IntermediatesError, RootError, PolicyError, DialError,
APIClientError, CSRError, CTError, CertStoreError, OCSPError:
// no-op, just use the error
default:
panic(fmt.Sprintf("Unsupported CFSSL error type: %d.",
category))
}
return &Error{ErrorCode: errorCode, Message: err.Error()}
} | [
"func",
"Wrap",
"(",
"category",
"Category",
",",
"reason",
"Reason",
",",
"err",
"error",
")",
"*",
"Error",
"{",
"errorCode",
":=",
"int",
"(",
"category",
")",
"+",
"int",
"(",
"reason",
")",
"\n",
"if",
"err",
"==",
"nil",
"{",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// do not double wrap a error",
"switch",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"Error",
":",
"panic",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"switch",
"category",
"{",
"case",
"CertificateError",
":",
"// given VerifyFailed , report the status with more detailed status code",
"// for some certificate errors we care.",
"if",
"reason",
"==",
"VerifyFailed",
"{",
"switch",
"errorType",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"x509",
".",
"CertificateInvalidError",
":",
"errorCode",
"+=",
"certificateInvalid",
"+",
"int",
"(",
"errorType",
".",
"Reason",
")",
"\n",
"case",
"x509",
".",
"UnknownAuthorityError",
":",
"errorCode",
"+=",
"unknownAuthority",
"\n",
"}",
"\n",
"}",
"\n",
"case",
"PrivateKeyError",
",",
"IntermediatesError",
",",
"RootError",
",",
"PolicyError",
",",
"DialError",
",",
"APIClientError",
",",
"CSRError",
",",
"CTError",
",",
"CertStoreError",
",",
"OCSPError",
":",
"// no-op, just use the error",
"default",
":",
"panic",
"(",
"fmt",
".",
"Sprintf",
"(",
"\"",
"\"",
",",
"category",
")",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"Error",
"{",
"ErrorCode",
":",
"errorCode",
",",
"Message",
":",
"err",
".",
"Error",
"(",
")",
"}",
"\n\n",
"}"
] | // Wrap returns an error that contains the given error and an error code derived from
// the given category, reason and the error. Currently, to avoid confusion, it is not
// allowed to create an error of category Success | [
"Wrap",
"returns",
"an",
"error",
"that",
"contains",
"the",
"given",
"error",
"and",
"an",
"error",
"code",
"derived",
"from",
"the",
"given",
"category",
"reason",
"and",
"the",
"error",
".",
"Currently",
"to",
"avoid",
"confusion",
"it",
"is",
"not",
"allowed",
"to",
"create",
"an",
"error",
"of",
"category",
"Success"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/errors/error.go#L404-L438 | train |
cloudflare/cfssl | scan/scan_common.go | multiscan | func multiscan(host string, scan func(string) (Grade, Output, error)) (grade Grade, output Output, err error) {
domain, port, _ := net.SplitHostPort(host)
var addrs []string
addrs, err = net.LookupHost(domain)
if err != nil {
return
}
grade = Good
out := make(map[string]Output)
for _, addr := range addrs {
var g Grade
var o Output
g, o, err = scan(net.JoinHostPort(addr, port))
if err != nil {
grade = Bad
return
}
if g < grade {
grade = g
}
out[addr] = o
}
output = out
return
} | go | func multiscan(host string, scan func(string) (Grade, Output, error)) (grade Grade, output Output, err error) {
domain, port, _ := net.SplitHostPort(host)
var addrs []string
addrs, err = net.LookupHost(domain)
if err != nil {
return
}
grade = Good
out := make(map[string]Output)
for _, addr := range addrs {
var g Grade
var o Output
g, o, err = scan(net.JoinHostPort(addr, port))
if err != nil {
grade = Bad
return
}
if g < grade {
grade = g
}
out[addr] = o
}
output = out
return
} | [
"func",
"multiscan",
"(",
"host",
"string",
",",
"scan",
"func",
"(",
"string",
")",
"(",
"Grade",
",",
"Output",
",",
"error",
")",
")",
"(",
"grade",
"Grade",
",",
"output",
"Output",
",",
"err",
"error",
")",
"{",
"domain",
",",
"port",
",",
"_",
":=",
"net",
".",
"SplitHostPort",
"(",
"host",
")",
"\n",
"var",
"addrs",
"[",
"]",
"string",
"\n",
"addrs",
",",
"err",
"=",
"net",
".",
"LookupHost",
"(",
"domain",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"grade",
"=",
"Good",
"\n",
"out",
":=",
"make",
"(",
"map",
"[",
"string",
"]",
"Output",
")",
"\n\n",
"for",
"_",
",",
"addr",
":=",
"range",
"addrs",
"{",
"var",
"g",
"Grade",
"\n",
"var",
"o",
"Output",
"\n\n",
"g",
",",
"o",
",",
"err",
"=",
"scan",
"(",
"net",
".",
"JoinHostPort",
"(",
"addr",
",",
"port",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"grade",
"=",
"Bad",
"\n",
"return",
"\n",
"}",
"\n\n",
"if",
"g",
"<",
"grade",
"{",
"grade",
"=",
"g",
"\n",
"}",
"\n\n",
"out",
"[",
"addr",
"]",
"=",
"o",
"\n",
"}",
"\n",
"output",
"=",
"out",
"\n",
"return",
"\n",
"}"
] | // multiscan scans all DNS addresses returned for the host, returning the lowest grade
// and the concatenation of all the output. | [
"multiscan",
"scans",
"all",
"DNS",
"addresses",
"returned",
"for",
"the",
"host",
"returning",
"the",
"lowest",
"grade",
"and",
"the",
"concatenation",
"of",
"all",
"the",
"output",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/scan_common.go#L62-L91 | train |
cloudflare/cfssl | scan/scan_common.go | Scan | func (s *Scanner) Scan(addr, hostname string) (Grade, Output, error) {
grade, output, err := s.scan(addr, hostname)
if err != nil {
log.Debugf("scan: %v", err)
return grade, output, err
}
return grade, output, err
} | go | func (s *Scanner) Scan(addr, hostname string) (Grade, Output, error) {
grade, output, err := s.scan(addr, hostname)
if err != nil {
log.Debugf("scan: %v", err)
return grade, output, err
}
return grade, output, err
} | [
"func",
"(",
"s",
"*",
"Scanner",
")",
"Scan",
"(",
"addr",
",",
"hostname",
"string",
")",
"(",
"Grade",
",",
"Output",
",",
"error",
")",
"{",
"grade",
",",
"output",
",",
"err",
":=",
"s",
".",
"scan",
"(",
"addr",
",",
"hostname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"grade",
",",
"output",
",",
"err",
"\n",
"}",
"\n",
"return",
"grade",
",",
"output",
",",
"err",
"\n",
"}"
] | // Scan performs the scan to be performed on the given host and stores its result. | [
"Scan",
"performs",
"the",
"scan",
"to",
"be",
"performed",
"on",
"the",
"given",
"host",
"and",
"stores",
"its",
"result",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/scan_common.go#L102-L109 | train |
cloudflare/cfssl | scan/scan_common.go | RunScans | func (fs FamilySet) RunScans(host, ip, family, scanner string, timeout time.Duration) (map[string]FamilyResult, error) {
hostname, port, err := net.SplitHostPort(host)
if err != nil {
hostname = host
port = "443"
}
var addr string
if net.ParseIP(ip) != nil {
addr = net.JoinHostPort(ip, port)
} else {
addr = net.JoinHostPort(hostname, port)
}
familyRegexp, err := regexp.Compile(family)
if err != nil {
return nil, err
}
scannerRegexp, err := regexp.Compile(scanner)
if err != nil {
return nil, err
}
ctx := newContext(addr, hostname, familyRegexp, scannerRegexp, len(fs))
for familyName, family := range fs {
familyCtx := ctx.newfamilyContext(len(family.Scanners))
for scannerName, scanner := range family.Scanners {
go familyCtx.runScanner(familyName, scannerName, scanner)
}
}
return ctx.copyResults(timeout), nil
} | go | func (fs FamilySet) RunScans(host, ip, family, scanner string, timeout time.Duration) (map[string]FamilyResult, error) {
hostname, port, err := net.SplitHostPort(host)
if err != nil {
hostname = host
port = "443"
}
var addr string
if net.ParseIP(ip) != nil {
addr = net.JoinHostPort(ip, port)
} else {
addr = net.JoinHostPort(hostname, port)
}
familyRegexp, err := regexp.Compile(family)
if err != nil {
return nil, err
}
scannerRegexp, err := regexp.Compile(scanner)
if err != nil {
return nil, err
}
ctx := newContext(addr, hostname, familyRegexp, scannerRegexp, len(fs))
for familyName, family := range fs {
familyCtx := ctx.newfamilyContext(len(family.Scanners))
for scannerName, scanner := range family.Scanners {
go familyCtx.runScanner(familyName, scannerName, scanner)
}
}
return ctx.copyResults(timeout), nil
} | [
"func",
"(",
"fs",
"FamilySet",
")",
"RunScans",
"(",
"host",
",",
"ip",
",",
"family",
",",
"scanner",
"string",
",",
"timeout",
"time",
".",
"Duration",
")",
"(",
"map",
"[",
"string",
"]",
"FamilyResult",
",",
"error",
")",
"{",
"hostname",
",",
"port",
",",
"err",
":=",
"net",
".",
"SplitHostPort",
"(",
"host",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"hostname",
"=",
"host",
"\n",
"port",
"=",
"\"",
"\"",
"\n",
"}",
"\n\n",
"var",
"addr",
"string",
"\n",
"if",
"net",
".",
"ParseIP",
"(",
"ip",
")",
"!=",
"nil",
"{",
"addr",
"=",
"net",
".",
"JoinHostPort",
"(",
"ip",
",",
"port",
")",
"\n",
"}",
"else",
"{",
"addr",
"=",
"net",
".",
"JoinHostPort",
"(",
"hostname",
",",
"port",
")",
"\n",
"}",
"\n\n",
"familyRegexp",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"family",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"scannerRegexp",
",",
"err",
":=",
"regexp",
".",
"Compile",
"(",
"scanner",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"ctx",
":=",
"newContext",
"(",
"addr",
",",
"hostname",
",",
"familyRegexp",
",",
"scannerRegexp",
",",
"len",
"(",
"fs",
")",
")",
"\n",
"for",
"familyName",
",",
"family",
":=",
"range",
"fs",
"{",
"familyCtx",
":=",
"ctx",
".",
"newfamilyContext",
"(",
"len",
"(",
"family",
".",
"Scanners",
")",
")",
"\n",
"for",
"scannerName",
",",
"scanner",
":=",
"range",
"family",
".",
"Scanners",
"{",
"go",
"familyCtx",
".",
"runScanner",
"(",
"familyName",
",",
"scannerName",
",",
"scanner",
")",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"ctx",
".",
"copyResults",
"(",
"timeout",
")",
",",
"nil",
"\n",
"}"
] | // RunScans iterates over AllScans, running each scan that matches the family
// and scanner regular expressions concurrently. | [
"RunScans",
"iterates",
"over",
"AllScans",
"running",
"each",
"scan",
"that",
"matches",
"the",
"family",
"and",
"scanner",
"regular",
"expressions",
"concurrently",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/scan_common.go#L231-L264 | train |
cloudflare/cfssl | scan/scan_common.go | LoadRootCAs | func LoadRootCAs(caBundleFile string) (err error) {
if caBundleFile != "" {
log.Debugf("Loading scan RootCAs: %s", caBundleFile)
RootCAs, err = helpers.LoadPEMCertPool(caBundleFile)
}
return
} | go | func LoadRootCAs(caBundleFile string) (err error) {
if caBundleFile != "" {
log.Debugf("Loading scan RootCAs: %s", caBundleFile)
RootCAs, err = helpers.LoadPEMCertPool(caBundleFile)
}
return
} | [
"func",
"LoadRootCAs",
"(",
"caBundleFile",
"string",
")",
"(",
"err",
"error",
")",
"{",
"if",
"caBundleFile",
"!=",
"\"",
"\"",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"caBundleFile",
")",
"\n",
"RootCAs",
",",
"err",
"=",
"helpers",
".",
"LoadPEMCertPool",
"(",
"caBundleFile",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // LoadRootCAs loads the default root certificate authorities from file. | [
"LoadRootCAs",
"loads",
"the",
"default",
"root",
"certificate",
"authorities",
"from",
"file",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/scan_common.go#L267-L273 | train |
cloudflare/cfssl | signer/remote/remote.go | NewSigner | func NewSigner(policy *config.Signing) (*Signer, error) {
if policy != nil {
if !policy.Valid() {
return nil, cferr.New(cferr.PolicyError,
cferr.InvalidPolicy)
}
return &Signer{policy: policy}, nil
}
return nil, cferr.New(cferr.PolicyError,
cferr.InvalidPolicy)
} | go | func NewSigner(policy *config.Signing) (*Signer, error) {
if policy != nil {
if !policy.Valid() {
return nil, cferr.New(cferr.PolicyError,
cferr.InvalidPolicy)
}
return &Signer{policy: policy}, nil
}
return nil, cferr.New(cferr.PolicyError,
cferr.InvalidPolicy)
} | [
"func",
"NewSigner",
"(",
"policy",
"*",
"config",
".",
"Signing",
")",
"(",
"*",
"Signer",
",",
"error",
")",
"{",
"if",
"policy",
"!=",
"nil",
"{",
"if",
"!",
"policy",
".",
"Valid",
"(",
")",
"{",
"return",
"nil",
",",
"cferr",
".",
"New",
"(",
"cferr",
".",
"PolicyError",
",",
"cferr",
".",
"InvalidPolicy",
")",
"\n",
"}",
"\n",
"return",
"&",
"Signer",
"{",
"policy",
":",
"policy",
"}",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"cferr",
".",
"New",
"(",
"cferr",
".",
"PolicyError",
",",
"cferr",
".",
"InvalidPolicy",
")",
"\n",
"}"
] | // NewSigner creates a new remote Signer directly from a
// signing policy. | [
"NewSigner",
"creates",
"a",
"new",
"remote",
"Signer",
"directly",
"from",
"a",
"signing",
"policy",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/signer/remote/remote.go#L27-L38 | train |
cloudflare/cfssl | signer/remote/remote.go | Sign | func (s *Signer) Sign(req signer.SignRequest) (cert []byte, err error) {
resp, err := s.remoteOp(req, req.Profile, "sign")
if err != nil {
return
}
if cert, ok := resp.([]byte); ok {
return cert, nil
}
return
} | go | func (s *Signer) Sign(req signer.SignRequest) (cert []byte, err error) {
resp, err := s.remoteOp(req, req.Profile, "sign")
if err != nil {
return
}
if cert, ok := resp.([]byte); ok {
return cert, nil
}
return
} | [
"func",
"(",
"s",
"*",
"Signer",
")",
"Sign",
"(",
"req",
"signer",
".",
"SignRequest",
")",
"(",
"cert",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"resp",
",",
"err",
":=",
"s",
".",
"remoteOp",
"(",
"req",
",",
"req",
".",
"Profile",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"cert",
",",
"ok",
":=",
"resp",
".",
"(",
"[",
"]",
"byte",
")",
";",
"ok",
"{",
"return",
"cert",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Sign sends a signature request to the remote CFSSL server,
// receiving a signed certificate or an error in response. The hostname,
// csr, and profileName are used as with a local signing operation, and
// the label is used to select a signing root in a multi-root CA. | [
"Sign",
"sends",
"a",
"signature",
"request",
"to",
"the",
"remote",
"CFSSL",
"server",
"receiving",
"a",
"signed",
"certificate",
"or",
"an",
"error",
"in",
"response",
".",
"The",
"hostname",
"csr",
"and",
"profileName",
"are",
"used",
"as",
"with",
"a",
"local",
"signing",
"operation",
"and",
"the",
"label",
"is",
"used",
"to",
"select",
"a",
"signing",
"root",
"in",
"a",
"multi",
"-",
"root",
"CA",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/signer/remote/remote.go#L44-L53 | train |
cloudflare/cfssl | signer/remote/remote.go | Info | func (s *Signer) Info(req info.Req) (resp *info.Resp, err error) {
respInterface, err := s.remoteOp(req, req.Profile, "info")
if err != nil {
return
}
if resp, ok := respInterface.(*info.Resp); ok {
return resp, nil
}
return
} | go | func (s *Signer) Info(req info.Req) (resp *info.Resp, err error) {
respInterface, err := s.remoteOp(req, req.Profile, "info")
if err != nil {
return
}
if resp, ok := respInterface.(*info.Resp); ok {
return resp, nil
}
return
} | [
"func",
"(",
"s",
"*",
"Signer",
")",
"Info",
"(",
"req",
"info",
".",
"Req",
")",
"(",
"resp",
"*",
"info",
".",
"Resp",
",",
"err",
"error",
")",
"{",
"respInterface",
",",
"err",
":=",
"s",
".",
"remoteOp",
"(",
"req",
",",
"req",
".",
"Profile",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"if",
"resp",
",",
"ok",
":=",
"respInterface",
".",
"(",
"*",
"info",
".",
"Resp",
")",
";",
"ok",
"{",
"return",
"resp",
",",
"nil",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // Info sends an info request to the remote CFSSL server, receiving an
// Resp struct or an error in response. | [
"Info",
"sends",
"an",
"info",
"request",
"to",
"the",
"remote",
"CFSSL",
"server",
"receiving",
"an",
"Resp",
"struct",
"or",
"an",
"error",
"in",
"response",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/signer/remote/remote.go#L57-L66 | train |
cloudflare/cfssl | signer/remote/remote.go | remoteOp | func (s *Signer) remoteOp(req interface{}, profile, target string) (resp interface{}, err error) {
jsonData, err := json.Marshal(req)
if err != nil {
return nil, cferr.Wrap(cferr.APIClientError, cferr.JSONError, err)
}
p, err := signer.Profile(s, profile)
if err != nil {
return
}
server := client.NewServerTLS(p.RemoteServer, helpers.CreateTLSConfig(p.RemoteCAs, p.ClientCert))
if server == nil {
return nil, cferr.Wrap(cferr.PolicyError, cferr.InvalidRequest,
errors.New("failed to connect to remote"))
}
server.SetReqModifier(s.reqModifier)
// There's no auth provider for the "info" method
if target == "info" {
resp, err = server.Info(jsonData)
} else if p.RemoteProvider != nil {
resp, err = server.AuthSign(jsonData, nil, p.RemoteProvider)
} else {
resp, err = server.Sign(jsonData)
}
if err != nil {
return nil, err
}
return
} | go | func (s *Signer) remoteOp(req interface{}, profile, target string) (resp interface{}, err error) {
jsonData, err := json.Marshal(req)
if err != nil {
return nil, cferr.Wrap(cferr.APIClientError, cferr.JSONError, err)
}
p, err := signer.Profile(s, profile)
if err != nil {
return
}
server := client.NewServerTLS(p.RemoteServer, helpers.CreateTLSConfig(p.RemoteCAs, p.ClientCert))
if server == nil {
return nil, cferr.Wrap(cferr.PolicyError, cferr.InvalidRequest,
errors.New("failed to connect to remote"))
}
server.SetReqModifier(s.reqModifier)
// There's no auth provider for the "info" method
if target == "info" {
resp, err = server.Info(jsonData)
} else if p.RemoteProvider != nil {
resp, err = server.AuthSign(jsonData, nil, p.RemoteProvider)
} else {
resp, err = server.Sign(jsonData)
}
if err != nil {
return nil, err
}
return
} | [
"func",
"(",
"s",
"*",
"Signer",
")",
"remoteOp",
"(",
"req",
"interface",
"{",
"}",
",",
"profile",
",",
"target",
"string",
")",
"(",
"resp",
"interface",
"{",
"}",
",",
"err",
"error",
")",
"{",
"jsonData",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"cferr",
".",
"Wrap",
"(",
"cferr",
".",
"APIClientError",
",",
"cferr",
".",
"JSONError",
",",
"err",
")",
"\n",
"}",
"\n\n",
"p",
",",
"err",
":=",
"signer",
".",
"Profile",
"(",
"s",
",",
"profile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"server",
":=",
"client",
".",
"NewServerTLS",
"(",
"p",
".",
"RemoteServer",
",",
"helpers",
".",
"CreateTLSConfig",
"(",
"p",
".",
"RemoteCAs",
",",
"p",
".",
"ClientCert",
")",
")",
"\n",
"if",
"server",
"==",
"nil",
"{",
"return",
"nil",
",",
"cferr",
".",
"Wrap",
"(",
"cferr",
".",
"PolicyError",
",",
"cferr",
".",
"InvalidRequest",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"server",
".",
"SetReqModifier",
"(",
"s",
".",
"reqModifier",
")",
"\n\n",
"// There's no auth provider for the \"info\" method",
"if",
"target",
"==",
"\"",
"\"",
"{",
"resp",
",",
"err",
"=",
"server",
".",
"Info",
"(",
"jsonData",
")",
"\n",
"}",
"else",
"if",
"p",
".",
"RemoteProvider",
"!=",
"nil",
"{",
"resp",
",",
"err",
"=",
"server",
".",
"AuthSign",
"(",
"jsonData",
",",
"nil",
",",
"p",
".",
"RemoteProvider",
")",
"\n",
"}",
"else",
"{",
"resp",
",",
"err",
"=",
"server",
".",
"Sign",
"(",
"jsonData",
")",
"\n",
"}",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // Helper function to perform a remote sign or info request. | [
"Helper",
"function",
"to",
"perform",
"a",
"remote",
"sign",
"or",
"info",
"request",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/signer/remote/remote.go#L69-L102 | train |
cloudflare/cfssl | signer/universal/universal.go | fileBackedSigner | func fileBackedSigner(root *Root, policy *config.Signing) (signer.Signer, bool, error) {
keyFile := root.Config["key-file"]
certFile := root.Config["cert-file"]
if keyFile == "" {
return nil, false, nil
}
signer, err := local.NewSignerFromFile(certFile, keyFile, policy)
return signer, true, err
} | go | func fileBackedSigner(root *Root, policy *config.Signing) (signer.Signer, bool, error) {
keyFile := root.Config["key-file"]
certFile := root.Config["cert-file"]
if keyFile == "" {
return nil, false, nil
}
signer, err := local.NewSignerFromFile(certFile, keyFile, policy)
return signer, true, err
} | [
"func",
"fileBackedSigner",
"(",
"root",
"*",
"Root",
",",
"policy",
"*",
"config",
".",
"Signing",
")",
"(",
"signer",
".",
"Signer",
",",
"bool",
",",
"error",
")",
"{",
"keyFile",
":=",
"root",
".",
"Config",
"[",
"\"",
"\"",
"]",
"\n",
"certFile",
":=",
"root",
".",
"Config",
"[",
"\"",
"\"",
"]",
"\n\n",
"if",
"keyFile",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"false",
",",
"nil",
"\n",
"}",
"\n\n",
"signer",
",",
"err",
":=",
"local",
".",
"NewSignerFromFile",
"(",
"certFile",
",",
"keyFile",
",",
"policy",
")",
"\n",
"return",
"signer",
",",
"true",
",",
"err",
"\n",
"}"
] | // fileBackedSigner determines whether a file-backed local signer is supported. | [
"fileBackedSigner",
"determines",
"whether",
"a",
"file",
"-",
"backed",
"local",
"signer",
"is",
"supported",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/signer/universal/universal.go#L37-L47 | train |
cloudflare/cfssl | signer/universal/universal.go | getMatchingProfile | func (s *Signer) getMatchingProfile(profile string) (*config.SigningProfile, error) {
if profile == "" {
return s.policy.Default, nil
}
for p, signingProfile := range s.policy.Profiles {
if p == profile {
return signingProfile, nil
}
}
return nil, cferr.New(cferr.PolicyError, cferr.UnknownProfile)
} | go | func (s *Signer) getMatchingProfile(profile string) (*config.SigningProfile, error) {
if profile == "" {
return s.policy.Default, nil
}
for p, signingProfile := range s.policy.Profiles {
if p == profile {
return signingProfile, nil
}
}
return nil, cferr.New(cferr.PolicyError, cferr.UnknownProfile)
} | [
"func",
"(",
"s",
"*",
"Signer",
")",
"getMatchingProfile",
"(",
"profile",
"string",
")",
"(",
"*",
"config",
".",
"SigningProfile",
",",
"error",
")",
"{",
"if",
"profile",
"==",
"\"",
"\"",
"{",
"return",
"s",
".",
"policy",
".",
"Default",
",",
"nil",
"\n",
"}",
"\n\n",
"for",
"p",
",",
"signingProfile",
":=",
"range",
"s",
".",
"policy",
".",
"Profiles",
"{",
"if",
"p",
"==",
"profile",
"{",
"return",
"signingProfile",
",",
"nil",
"\n",
"}",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"cferr",
".",
"New",
"(",
"cferr",
".",
"PolicyError",
",",
"cferr",
".",
"UnknownProfile",
")",
"\n",
"}"
] | // getMatchingProfile returns the SigningProfile that matches the profile passed.
// if an empty profile string is passed it returns the default profile. | [
"getMatchingProfile",
"returns",
"the",
"SigningProfile",
"that",
"matches",
"the",
"profile",
"passed",
".",
"if",
"an",
"empty",
"profile",
"string",
"is",
"passed",
"it",
"returns",
"the",
"default",
"profile",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/signer/universal/universal.go#L143-L155 | train |
cloudflare/cfssl | signer/universal/universal.go | Sign | func (s *Signer) Sign(req signer.SignRequest) (cert []byte, err error) {
profile, err := s.getMatchingProfile(req.Profile)
if err != nil {
return cert, err
}
if profile.RemoteServer != "" {
return s.remote.Sign(req)
}
return s.local.Sign(req)
} | go | func (s *Signer) Sign(req signer.SignRequest) (cert []byte, err error) {
profile, err := s.getMatchingProfile(req.Profile)
if err != nil {
return cert, err
}
if profile.RemoteServer != "" {
return s.remote.Sign(req)
}
return s.local.Sign(req)
} | [
"func",
"(",
"s",
"*",
"Signer",
")",
"Sign",
"(",
"req",
"signer",
".",
"SignRequest",
")",
"(",
"cert",
"[",
"]",
"byte",
",",
"err",
"error",
")",
"{",
"profile",
",",
"err",
":=",
"s",
".",
"getMatchingProfile",
"(",
"req",
".",
"Profile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"cert",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"profile",
".",
"RemoteServer",
"!=",
"\"",
"\"",
"{",
"return",
"s",
".",
"remote",
".",
"Sign",
"(",
"req",
")",
"\n",
"}",
"\n",
"return",
"s",
".",
"local",
".",
"Sign",
"(",
"req",
")",
"\n\n",
"}"
] | // Sign sends a signature request to either the remote or local signer,
// receiving a signed certificate or an error in response. | [
"Sign",
"sends",
"a",
"signature",
"request",
"to",
"either",
"the",
"remote",
"or",
"local",
"signer",
"receiving",
"a",
"signed",
"certificate",
"or",
"an",
"error",
"in",
"response",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/signer/universal/universal.go#L159-L170 | train |
cloudflare/cfssl | signer/universal/universal.go | Info | func (s *Signer) Info(req info.Req) (resp *info.Resp, err error) {
profile, err := s.getMatchingProfile(req.Profile)
if err != nil {
return resp, err
}
if profile.RemoteServer != "" {
return s.remote.Info(req)
}
return s.local.Info(req)
} | go | func (s *Signer) Info(req info.Req) (resp *info.Resp, err error) {
profile, err := s.getMatchingProfile(req.Profile)
if err != nil {
return resp, err
}
if profile.RemoteServer != "" {
return s.remote.Info(req)
}
return s.local.Info(req)
} | [
"func",
"(",
"s",
"*",
"Signer",
")",
"Info",
"(",
"req",
"info",
".",
"Req",
")",
"(",
"resp",
"*",
"info",
".",
"Resp",
",",
"err",
"error",
")",
"{",
"profile",
",",
"err",
":=",
"s",
".",
"getMatchingProfile",
"(",
"req",
".",
"Profile",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"resp",
",",
"err",
"\n",
"}",
"\n\n",
"if",
"profile",
".",
"RemoteServer",
"!=",
"\"",
"\"",
"{",
"return",
"s",
".",
"remote",
".",
"Info",
"(",
"req",
")",
"\n",
"}",
"\n",
"return",
"s",
".",
"local",
".",
"Info",
"(",
"req",
")",
"\n\n",
"}"
] | // Info sends an info request to the remote or local CFSSL server
// receiving an Resp struct or an error in response. | [
"Info",
"sends",
"an",
"info",
"request",
"to",
"the",
"remote",
"or",
"local",
"CFSSL",
"server",
"receiving",
"an",
"Resp",
"struct",
"or",
"an",
"error",
"in",
"response",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/signer/universal/universal.go#L174-L185 | train |
cloudflare/cfssl | signer/universal/universal.go | SetDBAccessor | func (s *Signer) SetDBAccessor(dba certdb.Accessor) {
s.local.SetDBAccessor(dba)
} | go | func (s *Signer) SetDBAccessor(dba certdb.Accessor) {
s.local.SetDBAccessor(dba)
} | [
"func",
"(",
"s",
"*",
"Signer",
")",
"SetDBAccessor",
"(",
"dba",
"certdb",
".",
"Accessor",
")",
"{",
"s",
".",
"local",
".",
"SetDBAccessor",
"(",
"dba",
")",
"\n",
"}"
] | // SetDBAccessor sets the signer's cert db accessor. | [
"SetDBAccessor",
"sets",
"the",
"signer",
"s",
"cert",
"db",
"accessor",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/signer/universal/universal.go#L188-L190 | train |
cloudflare/cfssl | signer/universal/universal.go | SigAlgo | func (s *Signer) SigAlgo() x509.SignatureAlgorithm {
if s.local != nil {
return s.local.SigAlgo()
}
// currently remote.SigAlgo just returns
// x509.UnknownSignatureAlgorithm.
return s.remote.SigAlgo()
} | go | func (s *Signer) SigAlgo() x509.SignatureAlgorithm {
if s.local != nil {
return s.local.SigAlgo()
}
// currently remote.SigAlgo just returns
// x509.UnknownSignatureAlgorithm.
return s.remote.SigAlgo()
} | [
"func",
"(",
"s",
"*",
"Signer",
")",
"SigAlgo",
"(",
")",
"x509",
".",
"SignatureAlgorithm",
"{",
"if",
"s",
".",
"local",
"!=",
"nil",
"{",
"return",
"s",
".",
"local",
".",
"SigAlgo",
"(",
")",
"\n",
"}",
"\n\n",
"// currently remote.SigAlgo just returns",
"// x509.UnknownSignatureAlgorithm.",
"return",
"s",
".",
"remote",
".",
"SigAlgo",
"(",
")",
"\n",
"}"
] | // SigAlgo returns the RSA signer's signature algorithm. | [
"SigAlgo",
"returns",
"the",
"RSA",
"signer",
"s",
"signature",
"algorithm",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/signer/universal/universal.go#L204-L212 | train |
cloudflare/cfssl | scan/crypto/tls/cipher_suites.go | macSHA1 | func macSHA1(version uint16, key []byte) macFunction {
if version == VersionSSL30 {
mac := ssl30MAC{
h: sha1.New(),
key: make([]byte, len(key)),
}
copy(mac.key, key)
return mac
}
return tls10MAC{hmac.New(sha1.New, key)}
} | go | func macSHA1(version uint16, key []byte) macFunction {
if version == VersionSSL30 {
mac := ssl30MAC{
h: sha1.New(),
key: make([]byte, len(key)),
}
copy(mac.key, key)
return mac
}
return tls10MAC{hmac.New(sha1.New, key)}
} | [
"func",
"macSHA1",
"(",
"version",
"uint16",
",",
"key",
"[",
"]",
"byte",
")",
"macFunction",
"{",
"if",
"version",
"==",
"VersionSSL30",
"{",
"mac",
":=",
"ssl30MAC",
"{",
"h",
":",
"sha1",
".",
"New",
"(",
")",
",",
"key",
":",
"make",
"(",
"[",
"]",
"byte",
",",
"len",
"(",
"key",
")",
")",
",",
"}",
"\n",
"copy",
"(",
"mac",
".",
"key",
",",
"key",
")",
"\n",
"return",
"mac",
"\n",
"}",
"\n",
"return",
"tls10MAC",
"{",
"hmac",
".",
"New",
"(",
"sha1",
".",
"New",
",",
"key",
")",
"}",
"\n",
"}"
] | // macSHA1 returns a macFunction for the given protocol version. | [
"macSHA1",
"returns",
"a",
"macFunction",
"for",
"the",
"given",
"protocol",
"version",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/tls/cipher_suites.go#L119-L129 | train |
cloudflare/cfssl | scan/crypto/tls/cipher_suites.go | mutualCipherSuite | func mutualCipherSuite(have []uint16, want uint16) *cipherSuite {
for _, id := range have {
if id == want {
for _, suite := range cipherSuites {
if suite.id == want {
return suite
}
}
return nil
}
}
return nil
} | go | func mutualCipherSuite(have []uint16, want uint16) *cipherSuite {
for _, id := range have {
if id == want {
for _, suite := range cipherSuites {
if suite.id == want {
return suite
}
}
return nil
}
}
return nil
} | [
"func",
"mutualCipherSuite",
"(",
"have",
"[",
"]",
"uint16",
",",
"want",
"uint16",
")",
"*",
"cipherSuite",
"{",
"for",
"_",
",",
"id",
":=",
"range",
"have",
"{",
"if",
"id",
"==",
"want",
"{",
"for",
"_",
",",
"suite",
":=",
"range",
"cipherSuites",
"{",
"if",
"suite",
".",
"id",
"==",
"want",
"{",
"return",
"suite",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // mutualCipherSuite returns a cipherSuite given a list of supported
// ciphersuites and the id requested by the peer. | [
"mutualCipherSuite",
"returns",
"a",
"cipherSuite",
"given",
"a",
"list",
"of",
"supported",
"ciphersuites",
"and",
"the",
"id",
"requested",
"by",
"the",
"peer",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/tls/cipher_suites.go#L250-L262 | train |
cloudflare/cfssl | scan/crypto/rsa/rsa.go | Validate | func (priv *PrivateKey) Validate() error {
if err := checkPub(&priv.PublicKey); err != nil {
return err
}
// Check that Πprimes == n.
modulus := new(big.Int).Set(bigOne)
for _, prime := range priv.Primes {
// Any primes ≤ 1 will cause divide-by-zero panics later.
if prime.Cmp(bigOne) <= 0 {
return errors.New("crypto/rsa: invalid prime value")
}
modulus.Mul(modulus, prime)
}
if modulus.Cmp(priv.N) != 0 {
return errors.New("crypto/rsa: invalid modulus")
}
// Check that de ≡ 1 mod p-1, for each prime.
// This implies that e is coprime to each p-1 as e has a multiplicative
// inverse. Therefore e is coprime to lcm(p-1,q-1,r-1,...) =
// exponent(ℤ/nℤ). It also implies that a^de ≡ a mod p as a^(p-1) ≡ 1
// mod p. Thus a^de ≡ a mod n for all a coprime to n, as required.
congruence := new(big.Int)
de := new(big.Int).SetInt64(int64(priv.E))
de.Mul(de, priv.D)
for _, prime := range priv.Primes {
pminus1 := new(big.Int).Sub(prime, bigOne)
congruence.Mod(de, pminus1)
if congruence.Cmp(bigOne) != 0 {
return errors.New("crypto/rsa: invalid exponents")
}
}
return nil
} | go | func (priv *PrivateKey) Validate() error {
if err := checkPub(&priv.PublicKey); err != nil {
return err
}
// Check that Πprimes == n.
modulus := new(big.Int).Set(bigOne)
for _, prime := range priv.Primes {
// Any primes ≤ 1 will cause divide-by-zero panics later.
if prime.Cmp(bigOne) <= 0 {
return errors.New("crypto/rsa: invalid prime value")
}
modulus.Mul(modulus, prime)
}
if modulus.Cmp(priv.N) != 0 {
return errors.New("crypto/rsa: invalid modulus")
}
// Check that de ≡ 1 mod p-1, for each prime.
// This implies that e is coprime to each p-1 as e has a multiplicative
// inverse. Therefore e is coprime to lcm(p-1,q-1,r-1,...) =
// exponent(ℤ/nℤ). It also implies that a^de ≡ a mod p as a^(p-1) ≡ 1
// mod p. Thus a^de ≡ a mod n for all a coprime to n, as required.
congruence := new(big.Int)
de := new(big.Int).SetInt64(int64(priv.E))
de.Mul(de, priv.D)
for _, prime := range priv.Primes {
pminus1 := new(big.Int).Sub(prime, bigOne)
congruence.Mod(de, pminus1)
if congruence.Cmp(bigOne) != 0 {
return errors.New("crypto/rsa: invalid exponents")
}
}
return nil
} | [
"func",
"(",
"priv",
"*",
"PrivateKey",
")",
"Validate",
"(",
")",
"error",
"{",
"if",
"err",
":=",
"checkPub",
"(",
"&",
"priv",
".",
"PublicKey",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"// Check that Πprimes == n.",
"modulus",
":=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"Set",
"(",
"bigOne",
")",
"\n",
"for",
"_",
",",
"prime",
":=",
"range",
"priv",
".",
"Primes",
"{",
"// Any primes ≤ 1 will cause divide-by-zero panics later.",
"if",
"prime",
".",
"Cmp",
"(",
"bigOne",
")",
"<=",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"modulus",
".",
"Mul",
"(",
"modulus",
",",
"prime",
")",
"\n",
"}",
"\n",
"if",
"modulus",
".",
"Cmp",
"(",
"priv",
".",
"N",
")",
"!=",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"// Check that de ≡ 1 mod p-1, for each prime.",
"// This implies that e is coprime to each p-1 as e has a multiplicative",
"// inverse. Therefore e is coprime to lcm(p-1,q-1,r-1,...) =",
"// exponent(ℤ/nℤ). It also implies that a^de ≡ a mod p as a^(p-1) ≡ 1",
"// mod p. Thus a^de ≡ a mod n for all a coprime to n, as required.",
"congruence",
":=",
"new",
"(",
"big",
".",
"Int",
")",
"\n",
"de",
":=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"SetInt64",
"(",
"int64",
"(",
"priv",
".",
"E",
")",
")",
"\n",
"de",
".",
"Mul",
"(",
"de",
",",
"priv",
".",
"D",
")",
"\n",
"for",
"_",
",",
"prime",
":=",
"range",
"priv",
".",
"Primes",
"{",
"pminus1",
":=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"Sub",
"(",
"prime",
",",
"bigOne",
")",
"\n",
"congruence",
".",
"Mod",
"(",
"de",
",",
"pminus1",
")",
"\n",
"if",
"congruence",
".",
"Cmp",
"(",
"bigOne",
")",
"!=",
"0",
"{",
"return",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}"
] | // Validate performs basic sanity checks on the key.
// It returns nil if the key is valid, or else an error describing a problem. | [
"Validate",
"performs",
"basic",
"sanity",
"checks",
"on",
"the",
"key",
".",
"It",
"returns",
"nil",
"if",
"the",
"key",
"is",
"valid",
"or",
"else",
"an",
"error",
"describing",
"a",
"problem",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/rsa/rsa.go#L156-L190 | train |
cloudflare/cfssl | scan/crypto/rsa/rsa.go | incCounter | func incCounter(c *[4]byte) {
if c[3]++; c[3] != 0 {
return
}
if c[2]++; c[2] != 0 {
return
}
if c[1]++; c[1] != 0 {
return
}
c[0]++
} | go | func incCounter(c *[4]byte) {
if c[3]++; c[3] != 0 {
return
}
if c[2]++; c[2] != 0 {
return
}
if c[1]++; c[1] != 0 {
return
}
c[0]++
} | [
"func",
"incCounter",
"(",
"c",
"*",
"[",
"4",
"]",
"byte",
")",
"{",
"if",
"c",
"[",
"3",
"]",
"++",
";",
"c",
"[",
"3",
"]",
"!=",
"0",
"{",
"return",
"\n",
"}",
"\n",
"if",
"c",
"[",
"2",
"]",
"++",
";",
"c",
"[",
"2",
"]",
"!=",
"0",
"{",
"return",
"\n",
"}",
"\n",
"if",
"c",
"[",
"1",
"]",
"++",
";",
"c",
"[",
"1",
"]",
"!=",
"0",
"{",
"return",
"\n",
"}",
"\n",
"c",
"[",
"0",
"]",
"++",
"\n",
"}"
] | // incCounter increments a four byte, big-endian counter. | [
"incCounter",
"increments",
"a",
"four",
"byte",
"big",
"-",
"endian",
"counter",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/rsa/rsa.go#L290-L301 | train |
cloudflare/cfssl | scan/crypto/rsa/rsa.go | Precompute | func (priv *PrivateKey) Precompute() {
if priv.Precomputed.Dp != nil {
return
}
priv.Precomputed.Dp = new(big.Int).Sub(priv.Primes[0], bigOne)
priv.Precomputed.Dp.Mod(priv.D, priv.Precomputed.Dp)
priv.Precomputed.Dq = new(big.Int).Sub(priv.Primes[1], bigOne)
priv.Precomputed.Dq.Mod(priv.D, priv.Precomputed.Dq)
priv.Precomputed.Qinv = new(big.Int).ModInverse(priv.Primes[1], priv.Primes[0])
r := new(big.Int).Mul(priv.Primes[0], priv.Primes[1])
priv.Precomputed.CRTValues = make([]CRTValue, len(priv.Primes)-2)
for i := 2; i < len(priv.Primes); i++ {
prime := priv.Primes[i]
values := &priv.Precomputed.CRTValues[i-2]
values.Exp = new(big.Int).Sub(prime, bigOne)
values.Exp.Mod(priv.D, values.Exp)
values.R = new(big.Int).Set(r)
values.Coeff = new(big.Int).ModInverse(r, prime)
r.Mul(r, prime)
}
} | go | func (priv *PrivateKey) Precompute() {
if priv.Precomputed.Dp != nil {
return
}
priv.Precomputed.Dp = new(big.Int).Sub(priv.Primes[0], bigOne)
priv.Precomputed.Dp.Mod(priv.D, priv.Precomputed.Dp)
priv.Precomputed.Dq = new(big.Int).Sub(priv.Primes[1], bigOne)
priv.Precomputed.Dq.Mod(priv.D, priv.Precomputed.Dq)
priv.Precomputed.Qinv = new(big.Int).ModInverse(priv.Primes[1], priv.Primes[0])
r := new(big.Int).Mul(priv.Primes[0], priv.Primes[1])
priv.Precomputed.CRTValues = make([]CRTValue, len(priv.Primes)-2)
for i := 2; i < len(priv.Primes); i++ {
prime := priv.Primes[i]
values := &priv.Precomputed.CRTValues[i-2]
values.Exp = new(big.Int).Sub(prime, bigOne)
values.Exp.Mod(priv.D, values.Exp)
values.R = new(big.Int).Set(r)
values.Coeff = new(big.Int).ModInverse(r, prime)
r.Mul(r, prime)
}
} | [
"func",
"(",
"priv",
"*",
"PrivateKey",
")",
"Precompute",
"(",
")",
"{",
"if",
"priv",
".",
"Precomputed",
".",
"Dp",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"priv",
".",
"Precomputed",
".",
"Dp",
"=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"Sub",
"(",
"priv",
".",
"Primes",
"[",
"0",
"]",
",",
"bigOne",
")",
"\n",
"priv",
".",
"Precomputed",
".",
"Dp",
".",
"Mod",
"(",
"priv",
".",
"D",
",",
"priv",
".",
"Precomputed",
".",
"Dp",
")",
"\n\n",
"priv",
".",
"Precomputed",
".",
"Dq",
"=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"Sub",
"(",
"priv",
".",
"Primes",
"[",
"1",
"]",
",",
"bigOne",
")",
"\n",
"priv",
".",
"Precomputed",
".",
"Dq",
".",
"Mod",
"(",
"priv",
".",
"D",
",",
"priv",
".",
"Precomputed",
".",
"Dq",
")",
"\n\n",
"priv",
".",
"Precomputed",
".",
"Qinv",
"=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"ModInverse",
"(",
"priv",
".",
"Primes",
"[",
"1",
"]",
",",
"priv",
".",
"Primes",
"[",
"0",
"]",
")",
"\n\n",
"r",
":=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"Mul",
"(",
"priv",
".",
"Primes",
"[",
"0",
"]",
",",
"priv",
".",
"Primes",
"[",
"1",
"]",
")",
"\n",
"priv",
".",
"Precomputed",
".",
"CRTValues",
"=",
"make",
"(",
"[",
"]",
"CRTValue",
",",
"len",
"(",
"priv",
".",
"Primes",
")",
"-",
"2",
")",
"\n",
"for",
"i",
":=",
"2",
";",
"i",
"<",
"len",
"(",
"priv",
".",
"Primes",
")",
";",
"i",
"++",
"{",
"prime",
":=",
"priv",
".",
"Primes",
"[",
"i",
"]",
"\n",
"values",
":=",
"&",
"priv",
".",
"Precomputed",
".",
"CRTValues",
"[",
"i",
"-",
"2",
"]",
"\n\n",
"values",
".",
"Exp",
"=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"Sub",
"(",
"prime",
",",
"bigOne",
")",
"\n",
"values",
".",
"Exp",
".",
"Mod",
"(",
"priv",
".",
"D",
",",
"values",
".",
"Exp",
")",
"\n\n",
"values",
".",
"R",
"=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"Set",
"(",
"r",
")",
"\n",
"values",
".",
"Coeff",
"=",
"new",
"(",
"big",
".",
"Int",
")",
".",
"ModInverse",
"(",
"r",
",",
"prime",
")",
"\n\n",
"r",
".",
"Mul",
"(",
"r",
",",
"prime",
")",
"\n",
"}",
"\n",
"}"
] | // Precompute performs some calculations that speed up private key operations
// in the future. | [
"Precompute",
"performs",
"some",
"calculations",
"that",
"speed",
"up",
"private",
"key",
"operations",
"in",
"the",
"future",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/rsa/rsa.go#L431-L458 | train |
cloudflare/cfssl | scan/crypto/rsa/rsa.go | leftPad | func leftPad(input []byte, size int) (out []byte) {
n := len(input)
if n > size {
n = size
}
out = make([]byte, size)
copy(out[len(out)-n:], input)
return
} | go | func leftPad(input []byte, size int) (out []byte) {
n := len(input)
if n > size {
n = size
}
out = make([]byte, size)
copy(out[len(out)-n:], input)
return
} | [
"func",
"leftPad",
"(",
"input",
"[",
"]",
"byte",
",",
"size",
"int",
")",
"(",
"out",
"[",
"]",
"byte",
")",
"{",
"n",
":=",
"len",
"(",
"input",
")",
"\n",
"if",
"n",
">",
"size",
"{",
"n",
"=",
"size",
"\n",
"}",
"\n",
"out",
"=",
"make",
"(",
"[",
"]",
"byte",
",",
"size",
")",
"\n",
"copy",
"(",
"out",
"[",
"len",
"(",
"out",
")",
"-",
"n",
":",
"]",
",",
"input",
")",
"\n",
"return",
"\n",
"}"
] | // leftPad returns a new slice of length size. The contents of input are right
// aligned in the new slice. | [
"leftPad",
"returns",
"a",
"new",
"slice",
"of",
"length",
"size",
".",
"The",
"contents",
"of",
"input",
"are",
"right",
"aligned",
"in",
"the",
"new",
"slice",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/rsa/rsa.go#L638-L646 | train |
cloudflare/cfssl | scan/pki.go | getChain | func getChain(addr string, config *tls.Config) (chain []*x509.Certificate, err error) {
var conn *tls.Conn
conn, err = tls.DialWithDialer(Dialer, Network, addr, config)
if err != nil {
return
}
err = conn.Close()
if err != nil {
return
}
chain = conn.ConnectionState().PeerCertificates
if len(chain) == 0 {
err = fmt.Errorf("%s returned empty certificate chain", addr)
}
return
} | go | func getChain(addr string, config *tls.Config) (chain []*x509.Certificate, err error) {
var conn *tls.Conn
conn, err = tls.DialWithDialer(Dialer, Network, addr, config)
if err != nil {
return
}
err = conn.Close()
if err != nil {
return
}
chain = conn.ConnectionState().PeerCertificates
if len(chain) == 0 {
err = fmt.Errorf("%s returned empty certificate chain", addr)
}
return
} | [
"func",
"getChain",
"(",
"addr",
"string",
",",
"config",
"*",
"tls",
".",
"Config",
")",
"(",
"chain",
"[",
"]",
"*",
"x509",
".",
"Certificate",
",",
"err",
"error",
")",
"{",
"var",
"conn",
"*",
"tls",
".",
"Conn",
"\n",
"conn",
",",
"err",
"=",
"tls",
".",
"DialWithDialer",
"(",
"Dialer",
",",
"Network",
",",
"addr",
",",
"config",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"err",
"=",
"conn",
".",
"Close",
"(",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"chain",
"=",
"conn",
".",
"ConnectionState",
"(",
")",
".",
"PeerCertificates",
"\n",
"if",
"len",
"(",
"chain",
")",
"==",
"0",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"addr",
")",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // getChain is a helper function that retreives the host's certificate chain. | [
"getChain",
"is",
"a",
"helper",
"function",
"that",
"retreives",
"the",
"host",
"s",
"certificate",
"chain",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/pki.go#L34-L51 | train |
cloudflare/cfssl | ocsp/responder.go | Response | func (src InMemorySource) Response(request *ocsp.Request) ([]byte, http.Header, error) {
response, present := src[request.SerialNumber.String()]
if !present {
return nil, nil, ErrNotFound
}
return response, nil, nil
} | go | func (src InMemorySource) Response(request *ocsp.Request) ([]byte, http.Header, error) {
response, present := src[request.SerialNumber.String()]
if !present {
return nil, nil, ErrNotFound
}
return response, nil, nil
} | [
"func",
"(",
"src",
"InMemorySource",
")",
"Response",
"(",
"request",
"*",
"ocsp",
".",
"Request",
")",
"(",
"[",
"]",
"byte",
",",
"http",
".",
"Header",
",",
"error",
")",
"{",
"response",
",",
"present",
":=",
"src",
"[",
"request",
".",
"SerialNumber",
".",
"String",
"(",
")",
"]",
"\n",
"if",
"!",
"present",
"{",
"return",
"nil",
",",
"nil",
",",
"ErrNotFound",
"\n",
"}",
"\n",
"return",
"response",
",",
"nil",
",",
"nil",
"\n",
"}"
] | // Response looks up an OCSP response to provide for a given request.
// InMemorySource looks up a response purely based on serial number,
// without regard to what issuer the request is asking for. | [
"Response",
"looks",
"up",
"an",
"OCSP",
"response",
"to",
"provide",
"for",
"a",
"given",
"request",
".",
"InMemorySource",
"looks",
"up",
"a",
"response",
"purely",
"based",
"on",
"serial",
"number",
"without",
"regard",
"to",
"what",
"issuer",
"the",
"request",
"is",
"asking",
"for",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/ocsp/responder.go#L63-L69 | train |
cloudflare/cfssl | ocsp/responder.go | Response | func (src DBSource) Response(req *ocsp.Request) ([]byte, http.Header, error) {
if req == nil {
return nil, nil, errors.New("called with nil request")
}
aki := hex.EncodeToString(req.IssuerKeyHash)
sn := req.SerialNumber
if sn == nil {
return nil, nil, errors.New("request contains no serial")
}
strSN := sn.String()
if src.Accessor == nil {
log.Errorf("No DB Accessor")
return nil, nil, errors.New("called with nil DB accessor")
}
records, err := src.Accessor.GetOCSP(strSN, aki)
// Response() logs when there are errors obtaining the OCSP response
// and returns nil, false.
if err != nil {
log.Errorf("Error obtaining OCSP response: %s", err)
return nil, nil, fmt.Errorf("failed to obtain OCSP response: %s", err)
}
if len(records) == 0 {
return nil, nil, ErrNotFound
}
// Response() finds the OCSPRecord with the expiration date furthest in the future.
cur := records[0]
for _, rec := range records {
if rec.Expiry.After(cur.Expiry) {
cur = rec
}
}
return []byte(cur.Body), nil, nil
} | go | func (src DBSource) Response(req *ocsp.Request) ([]byte, http.Header, error) {
if req == nil {
return nil, nil, errors.New("called with nil request")
}
aki := hex.EncodeToString(req.IssuerKeyHash)
sn := req.SerialNumber
if sn == nil {
return nil, nil, errors.New("request contains no serial")
}
strSN := sn.String()
if src.Accessor == nil {
log.Errorf("No DB Accessor")
return nil, nil, errors.New("called with nil DB accessor")
}
records, err := src.Accessor.GetOCSP(strSN, aki)
// Response() logs when there are errors obtaining the OCSP response
// and returns nil, false.
if err != nil {
log.Errorf("Error obtaining OCSP response: %s", err)
return nil, nil, fmt.Errorf("failed to obtain OCSP response: %s", err)
}
if len(records) == 0 {
return nil, nil, ErrNotFound
}
// Response() finds the OCSPRecord with the expiration date furthest in the future.
cur := records[0]
for _, rec := range records {
if rec.Expiry.After(cur.Expiry) {
cur = rec
}
}
return []byte(cur.Body), nil, nil
} | [
"func",
"(",
"src",
"DBSource",
")",
"Response",
"(",
"req",
"*",
"ocsp",
".",
"Request",
")",
"(",
"[",
"]",
"byte",
",",
"http",
".",
"Header",
",",
"error",
")",
"{",
"if",
"req",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"aki",
":=",
"hex",
".",
"EncodeToString",
"(",
"req",
".",
"IssuerKeyHash",
")",
"\n",
"sn",
":=",
"req",
".",
"SerialNumber",
"\n\n",
"if",
"sn",
"==",
"nil",
"{",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"strSN",
":=",
"sn",
".",
"String",
"(",
")",
"\n\n",
"if",
"src",
".",
"Accessor",
"==",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"records",
",",
"err",
":=",
"src",
".",
"Accessor",
".",
"GetOCSP",
"(",
"strSN",
",",
"aki",
")",
"\n\n",
"// Response() logs when there are errors obtaining the OCSP response",
"// and returns nil, false.",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"nil",
",",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"records",
")",
"==",
"0",
"{",
"return",
"nil",
",",
"nil",
",",
"ErrNotFound",
"\n",
"}",
"\n\n",
"// Response() finds the OCSPRecord with the expiration date furthest in the future.",
"cur",
":=",
"records",
"[",
"0",
"]",
"\n",
"for",
"_",
",",
"rec",
":=",
"range",
"records",
"{",
"if",
"rec",
".",
"Expiry",
".",
"After",
"(",
"cur",
".",
"Expiry",
")",
"{",
"cur",
"=",
"rec",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"[",
"]",
"byte",
"(",
"cur",
".",
"Body",
")",
",",
"nil",
",",
"nil",
"\n",
"}"
] | // Response implements cfssl.ocsp.responder.Source, which returns the
// OCSP response in the Database for the given request with the expiration
// date furthest in the future. | [
"Response",
"implements",
"cfssl",
".",
"ocsp",
".",
"responder",
".",
"Source",
"which",
"returns",
"the",
"OCSP",
"response",
"in",
"the",
"Database",
"for",
"the",
"given",
"request",
"with",
"the",
"expiration",
"date",
"furthest",
"in",
"the",
"future",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/ocsp/responder.go#L86-L124 | train |
cloudflare/cfssl | ocsp/responder.go | NewSourceFromDB | func NewSourceFromDB(DBConfigFile string) (Source, error) {
// Load DB from cofiguration file
db, err := dbconf.DBFromConfig(DBConfigFile)
if err != nil {
return nil, err
}
// Create accesor
accessor := sql.NewAccessor(db)
src := NewDBSource(accessor)
return src, nil
} | go | func NewSourceFromDB(DBConfigFile string) (Source, error) {
// Load DB from cofiguration file
db, err := dbconf.DBFromConfig(DBConfigFile)
if err != nil {
return nil, err
}
// Create accesor
accessor := sql.NewAccessor(db)
src := NewDBSource(accessor)
return src, nil
} | [
"func",
"NewSourceFromDB",
"(",
"DBConfigFile",
"string",
")",
"(",
"Source",
",",
"error",
")",
"{",
"// Load DB from cofiguration file",
"db",
",",
"err",
":=",
"dbconf",
".",
"DBFromConfig",
"(",
"DBConfigFile",
")",
"\n\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"// Create accesor",
"accessor",
":=",
"sql",
".",
"NewAccessor",
"(",
"db",
")",
"\n",
"src",
":=",
"NewDBSource",
"(",
"accessor",
")",
"\n\n",
"return",
"src",
",",
"nil",
"\n",
"}"
] | // NewSourceFromDB reads the given database configuration file
// and creates a database data source for use with the OCSP responder | [
"NewSourceFromDB",
"reads",
"the",
"given",
"database",
"configuration",
"file",
"and",
"creates",
"a",
"database",
"data",
"source",
"for",
"use",
"with",
"the",
"OCSP",
"responder"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/ocsp/responder.go#L165-L177 | train |
cloudflare/cfssl | ocsp/responder.go | NewResponder | func NewResponder(source Source, stats Stats) *Responder {
return &Responder{
Source: source,
stats: stats,
clk: clock.New(),
}
} | go | func NewResponder(source Source, stats Stats) *Responder {
return &Responder{
Source: source,
stats: stats,
clk: clock.New(),
}
} | [
"func",
"NewResponder",
"(",
"source",
"Source",
",",
"stats",
"Stats",
")",
"*",
"Responder",
"{",
"return",
"&",
"Responder",
"{",
"Source",
":",
"source",
",",
"stats",
":",
"stats",
",",
"clk",
":",
"clock",
".",
"New",
"(",
")",
",",
"}",
"\n",
"}"
] | // NewResponder instantiates a Responder with the give Source. | [
"NewResponder",
"instantiates",
"a",
"Responder",
"with",
"the",
"give",
"Source",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/ocsp/responder.go#L194-L200 | train |
cloudflare/cfssl | multiroot/config/config.go | ParseToRawMap | func ParseToRawMap(fileName string) (cfg RawMap, err error) {
var file *os.File
cfg = make(RawMap, 0)
file, err = os.Open(fileName)
if err != nil {
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
var currentSection string
for scanner.Scan() {
line := scanner.Text()
if commentLine.MatchString(line) {
continue
} else if blankLine.MatchString(line) {
continue
} else if configSection.MatchString(line) {
section := configSection.ReplaceAllString(line, "$1")
if !cfg.SectionInConfig(section) {
cfg[section] = make(map[string]string, 0)
}
currentSection = section
} else if configLine.MatchString(line) {
regex := configLine
if quotedConfigLine.MatchString(line) {
regex = quotedConfigLine
}
if currentSection == "" {
currentSection = defaultSection
if !cfg.SectionInConfig(currentSection) {
cfg[currentSection] = make(map[string]string, 0)
}
}
key := regex.ReplaceAllString(line, "$1")
val := regex.ReplaceAllString(line, "$2")
cfg[currentSection][key] = val
} else {
err = fmt.Errorf("invalid config file")
break
}
}
return
} | go | func ParseToRawMap(fileName string) (cfg RawMap, err error) {
var file *os.File
cfg = make(RawMap, 0)
file, err = os.Open(fileName)
if err != nil {
return
}
defer file.Close()
scanner := bufio.NewScanner(file)
var currentSection string
for scanner.Scan() {
line := scanner.Text()
if commentLine.MatchString(line) {
continue
} else if blankLine.MatchString(line) {
continue
} else if configSection.MatchString(line) {
section := configSection.ReplaceAllString(line, "$1")
if !cfg.SectionInConfig(section) {
cfg[section] = make(map[string]string, 0)
}
currentSection = section
} else if configLine.MatchString(line) {
regex := configLine
if quotedConfigLine.MatchString(line) {
regex = quotedConfigLine
}
if currentSection == "" {
currentSection = defaultSection
if !cfg.SectionInConfig(currentSection) {
cfg[currentSection] = make(map[string]string, 0)
}
}
key := regex.ReplaceAllString(line, "$1")
val := regex.ReplaceAllString(line, "$2")
cfg[currentSection][key] = val
} else {
err = fmt.Errorf("invalid config file")
break
}
}
return
} | [
"func",
"ParseToRawMap",
"(",
"fileName",
"string",
")",
"(",
"cfg",
"RawMap",
",",
"err",
"error",
")",
"{",
"var",
"file",
"*",
"os",
".",
"File",
"\n\n",
"cfg",
"=",
"make",
"(",
"RawMap",
",",
"0",
")",
"\n",
"file",
",",
"err",
"=",
"os",
".",
"Open",
"(",
"fileName",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n",
"scanner",
":=",
"bufio",
".",
"NewScanner",
"(",
"file",
")",
"\n\n",
"var",
"currentSection",
"string",
"\n",
"for",
"scanner",
".",
"Scan",
"(",
")",
"{",
"line",
":=",
"scanner",
".",
"Text",
"(",
")",
"\n\n",
"if",
"commentLine",
".",
"MatchString",
"(",
"line",
")",
"{",
"continue",
"\n",
"}",
"else",
"if",
"blankLine",
".",
"MatchString",
"(",
"line",
")",
"{",
"continue",
"\n",
"}",
"else",
"if",
"configSection",
".",
"MatchString",
"(",
"line",
")",
"{",
"section",
":=",
"configSection",
".",
"ReplaceAllString",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"if",
"!",
"cfg",
".",
"SectionInConfig",
"(",
"section",
")",
"{",
"cfg",
"[",
"section",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"0",
")",
"\n",
"}",
"\n",
"currentSection",
"=",
"section",
"\n",
"}",
"else",
"if",
"configLine",
".",
"MatchString",
"(",
"line",
")",
"{",
"regex",
":=",
"configLine",
"\n",
"if",
"quotedConfigLine",
".",
"MatchString",
"(",
"line",
")",
"{",
"regex",
"=",
"quotedConfigLine",
"\n",
"}",
"\n",
"if",
"currentSection",
"==",
"\"",
"\"",
"{",
"currentSection",
"=",
"defaultSection",
"\n",
"if",
"!",
"cfg",
".",
"SectionInConfig",
"(",
"currentSection",
")",
"{",
"cfg",
"[",
"currentSection",
"]",
"=",
"make",
"(",
"map",
"[",
"string",
"]",
"string",
",",
"0",
")",
"\n",
"}",
"\n",
"}",
"\n",
"key",
":=",
"regex",
".",
"ReplaceAllString",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"val",
":=",
"regex",
".",
"ReplaceAllString",
"(",
"line",
",",
"\"",
"\"",
")",
"\n",
"cfg",
"[",
"currentSection",
"]",
"[",
"key",
"]",
"=",
"val",
"\n",
"}",
"else",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
")",
"\n",
"break",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"\n",
"}"
] | // ParseToRawMap takes the filename as a string and returns a RawMap. | [
"ParseToRawMap",
"takes",
"the",
"filename",
"as",
"a",
"string",
"and",
"returns",
"a",
"RawMap",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/multiroot/config/config.go#L44-L89 | train |
cloudflare/cfssl | multiroot/config/config.go | SectionInConfig | func (c *RawMap) SectionInConfig(section string) bool {
for s := range *c {
if section == s {
return true
}
}
return false
} | go | func (c *RawMap) SectionInConfig(section string) bool {
for s := range *c {
if section == s {
return true
}
}
return false
} | [
"func",
"(",
"c",
"*",
"RawMap",
")",
"SectionInConfig",
"(",
"section",
"string",
")",
"bool",
"{",
"for",
"s",
":=",
"range",
"*",
"c",
"{",
"if",
"section",
"==",
"s",
"{",
"return",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"false",
"\n",
"}"
] | // SectionInConfig determines whether a section is in the configuration. | [
"SectionInConfig",
"determines",
"whether",
"a",
"section",
"is",
"in",
"the",
"configuration",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/multiroot/config/config.go#L92-L99 | train |
cloudflare/cfssl | multiroot/config/config.go | LoadRoot | func LoadRoot(cfg map[string]string) (*Root, error) {
var root Root
var err error
spec, ok := cfg["private"]
if !ok {
return nil, ErrMissingPrivateKey
}
certPath, ok := cfg["certificate"]
if !ok {
return nil, ErrMissingCertificatePath
}
configPath, ok := cfg["config"]
if !ok {
return nil, ErrMissingConfigPath
}
root.PrivateKey, err = parsePrivateKeySpec(spec, cfg)
if err != nil {
return nil, err
}
in, err := ioutil.ReadFile(certPath)
if err != nil {
return nil, err
}
root.Certificate, err = helpers.ParseCertificatePEM(in)
if err != nil {
return nil, err
}
conf, err := config.LoadFile(configPath)
if err != nil {
return nil, err
}
root.Config = conf.Signing
nets := cfg["nets"]
if nets != "" {
root.ACL, err = parseACL(nets)
if err != nil {
return nil, err
}
}
dbConfig := cfg["dbconfig"]
if dbConfig != "" {
db, err := dbconf.DBFromConfig(dbConfig)
if err != nil {
return nil, err
}
root.DB = db
}
return &root, nil
} | go | func LoadRoot(cfg map[string]string) (*Root, error) {
var root Root
var err error
spec, ok := cfg["private"]
if !ok {
return nil, ErrMissingPrivateKey
}
certPath, ok := cfg["certificate"]
if !ok {
return nil, ErrMissingCertificatePath
}
configPath, ok := cfg["config"]
if !ok {
return nil, ErrMissingConfigPath
}
root.PrivateKey, err = parsePrivateKeySpec(spec, cfg)
if err != nil {
return nil, err
}
in, err := ioutil.ReadFile(certPath)
if err != nil {
return nil, err
}
root.Certificate, err = helpers.ParseCertificatePEM(in)
if err != nil {
return nil, err
}
conf, err := config.LoadFile(configPath)
if err != nil {
return nil, err
}
root.Config = conf.Signing
nets := cfg["nets"]
if nets != "" {
root.ACL, err = parseACL(nets)
if err != nil {
return nil, err
}
}
dbConfig := cfg["dbconfig"]
if dbConfig != "" {
db, err := dbconf.DBFromConfig(dbConfig)
if err != nil {
return nil, err
}
root.DB = db
}
return &root, nil
} | [
"func",
"LoadRoot",
"(",
"cfg",
"map",
"[",
"string",
"]",
"string",
")",
"(",
"*",
"Root",
",",
"error",
")",
"{",
"var",
"root",
"Root",
"\n",
"var",
"err",
"error",
"\n",
"spec",
",",
"ok",
":=",
"cfg",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrMissingPrivateKey",
"\n",
"}",
"\n\n",
"certPath",
",",
"ok",
":=",
"cfg",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrMissingCertificatePath",
"\n",
"}",
"\n\n",
"configPath",
",",
"ok",
":=",
"cfg",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"nil",
",",
"ErrMissingConfigPath",
"\n",
"}",
"\n\n",
"root",
".",
"PrivateKey",
",",
"err",
"=",
"parsePrivateKeySpec",
"(",
"spec",
",",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"in",
",",
"err",
":=",
"ioutil",
".",
"ReadFile",
"(",
"certPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"root",
".",
"Certificate",
",",
"err",
"=",
"helpers",
".",
"ParseCertificatePEM",
"(",
"in",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"conf",
",",
"err",
":=",
"config",
".",
"LoadFile",
"(",
"configPath",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"root",
".",
"Config",
"=",
"conf",
".",
"Signing",
"\n\n",
"nets",
":=",
"cfg",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"nets",
"!=",
"\"",
"\"",
"{",
"root",
".",
"ACL",
",",
"err",
"=",
"parseACL",
"(",
"nets",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"}",
"\n\n",
"dbConfig",
":=",
"cfg",
"[",
"\"",
"\"",
"]",
"\n",
"if",
"dbConfig",
"!=",
"\"",
"\"",
"{",
"db",
",",
"err",
":=",
"dbconf",
".",
"DBFromConfig",
"(",
"dbConfig",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"root",
".",
"DB",
"=",
"db",
"\n",
"}",
"\n\n",
"return",
"&",
"root",
",",
"nil",
"\n",
"}"
] | // LoadRoot parses a config structure into a Root structure | [
"LoadRoot",
"parses",
"a",
"config",
"structure",
"into",
"a",
"Root",
"structure"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/multiroot/config/config.go#L111-L168 | train |
cloudflare/cfssl | multiroot/config/config.go | Parse | func Parse(filename string) (RootList, error) {
cfgMap, err := ParseToRawMap(filename)
if err != nil {
return nil, err
}
var rootList = RootList{}
for label, entries := range cfgMap {
root, err := LoadRoot(entries)
if err != nil {
return nil, err
}
rootList[label] = root
}
return rootList, nil
} | go | func Parse(filename string) (RootList, error) {
cfgMap, err := ParseToRawMap(filename)
if err != nil {
return nil, err
}
var rootList = RootList{}
for label, entries := range cfgMap {
root, err := LoadRoot(entries)
if err != nil {
return nil, err
}
rootList[label] = root
}
return rootList, nil
} | [
"func",
"Parse",
"(",
"filename",
"string",
")",
"(",
"RootList",
",",
"error",
")",
"{",
"cfgMap",
",",
"err",
":=",
"ParseToRawMap",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"var",
"rootList",
"=",
"RootList",
"{",
"}",
"\n",
"for",
"label",
",",
"entries",
":=",
"range",
"cfgMap",
"{",
"root",
",",
"err",
":=",
"LoadRoot",
"(",
"entries",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"rootList",
"[",
"label",
"]",
"=",
"root",
"\n",
"}",
"\n\n",
"return",
"rootList",
",",
"nil",
"\n",
"}"
] | // Parse loads a RootList from a file. | [
"Parse",
"loads",
"a",
"RootList",
"from",
"a",
"file",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/multiroot/config/config.go#L305-L322 | train |
cloudflare/cfssl | certdb/dbconf/db_config.go | LoadFile | func LoadFile(path string) (cfg *DBConfig, err error) {
log.Debugf("loading db configuration file from %s", path)
if path == "" {
return nil, cferr.Wrap(cferr.PolicyError, cferr.InvalidPolicy, errors.New("invalid path"))
}
var body []byte
body, err = ioutil.ReadFile(path)
if err != nil {
return nil, cferr.Wrap(cferr.PolicyError, cferr.InvalidPolicy, errors.New("could not read configuration file"))
}
cfg = &DBConfig{}
err = json.Unmarshal(body, &cfg)
if err != nil {
return nil, cferr.Wrap(cferr.PolicyError, cferr.InvalidPolicy,
errors.New("failed to unmarshal configuration: "+err.Error()))
}
if cfg.DataSourceName == "" || cfg.DriverName == "" {
return nil, cferr.Wrap(cferr.PolicyError, cferr.InvalidPolicy, errors.New("invalid db configuration"))
}
return
} | go | func LoadFile(path string) (cfg *DBConfig, err error) {
log.Debugf("loading db configuration file from %s", path)
if path == "" {
return nil, cferr.Wrap(cferr.PolicyError, cferr.InvalidPolicy, errors.New("invalid path"))
}
var body []byte
body, err = ioutil.ReadFile(path)
if err != nil {
return nil, cferr.Wrap(cferr.PolicyError, cferr.InvalidPolicy, errors.New("could not read configuration file"))
}
cfg = &DBConfig{}
err = json.Unmarshal(body, &cfg)
if err != nil {
return nil, cferr.Wrap(cferr.PolicyError, cferr.InvalidPolicy,
errors.New("failed to unmarshal configuration: "+err.Error()))
}
if cfg.DataSourceName == "" || cfg.DriverName == "" {
return nil, cferr.Wrap(cferr.PolicyError, cferr.InvalidPolicy, errors.New("invalid db configuration"))
}
return
} | [
"func",
"LoadFile",
"(",
"path",
"string",
")",
"(",
"cfg",
"*",
"DBConfig",
",",
"err",
"error",
")",
"{",
"log",
".",
"Debugf",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"if",
"path",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"cferr",
".",
"Wrap",
"(",
"cferr",
".",
"PolicyError",
",",
"cferr",
".",
"InvalidPolicy",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"var",
"body",
"[",
"]",
"byte",
"\n",
"body",
",",
"err",
"=",
"ioutil",
".",
"ReadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"cferr",
".",
"Wrap",
"(",
"cferr",
".",
"PolicyError",
",",
"cferr",
".",
"InvalidPolicy",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"cfg",
"=",
"&",
"DBConfig",
"{",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"cfg",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"cferr",
".",
"Wrap",
"(",
"cferr",
".",
"PolicyError",
",",
"cferr",
".",
"InvalidPolicy",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
"+",
"err",
".",
"Error",
"(",
")",
")",
")",
"\n",
"}",
"\n\n",
"if",
"cfg",
".",
"DataSourceName",
"==",
"\"",
"\"",
"||",
"cfg",
".",
"DriverName",
"==",
"\"",
"\"",
"{",
"return",
"nil",
",",
"cferr",
".",
"Wrap",
"(",
"cferr",
".",
"PolicyError",
",",
"cferr",
".",
"InvalidPolicy",
",",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}",
"\n\n",
"return",
"\n",
"}"
] | // LoadFile attempts to load the db configuration file stored at the path
// and returns the configuration. On error, it returns nil. | [
"LoadFile",
"attempts",
"to",
"load",
"the",
"db",
"configuration",
"file",
"stored",
"at",
"the",
"path",
"and",
"returns",
"the",
"configuration",
".",
"On",
"error",
"it",
"returns",
"nil",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/certdb/dbconf/db_config.go#L22-L46 | train |
cloudflare/cfssl | certdb/dbconf/db_config.go | DBFromConfig | func DBFromConfig(path string) (db *sqlx.DB, err error) {
var dbCfg *DBConfig
dbCfg, err = LoadFile(path)
if err != nil {
return nil, err
}
return sqlx.Open(dbCfg.DriverName, dbCfg.DataSourceName)
} | go | func DBFromConfig(path string) (db *sqlx.DB, err error) {
var dbCfg *DBConfig
dbCfg, err = LoadFile(path)
if err != nil {
return nil, err
}
return sqlx.Open(dbCfg.DriverName, dbCfg.DataSourceName)
} | [
"func",
"DBFromConfig",
"(",
"path",
"string",
")",
"(",
"db",
"*",
"sqlx",
".",
"DB",
",",
"err",
"error",
")",
"{",
"var",
"dbCfg",
"*",
"DBConfig",
"\n",
"dbCfg",
",",
"err",
"=",
"LoadFile",
"(",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"return",
"sqlx",
".",
"Open",
"(",
"dbCfg",
".",
"DriverName",
",",
"dbCfg",
".",
"DataSourceName",
")",
"\n",
"}"
] | // DBFromConfig opens a sql.DB from settings in a db config file | [
"DBFromConfig",
"opens",
"a",
"sql",
".",
"DB",
"from",
"settings",
"in",
"a",
"db",
"config",
"file"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/certdb/dbconf/db_config.go#L49-L57 | train |
cloudflare/cfssl | scan/crypto/sha512/sha512.go | New | func New() hash.Hash {
d := &digest{function: crypto.SHA512}
d.Reset()
return d
} | go | func New() hash.Hash {
d := &digest{function: crypto.SHA512}
d.Reset()
return d
} | [
"func",
"New",
"(",
")",
"hash",
".",
"Hash",
"{",
"d",
":=",
"&",
"digest",
"{",
"function",
":",
"crypto",
".",
"SHA512",
"}",
"\n",
"d",
".",
"Reset",
"(",
")",
"\n",
"return",
"d",
"\n",
"}"
] | // New returns a new hash.Hash computing the SHA-512 checksum. | [
"New",
"returns",
"a",
"new",
"hash",
".",
"Hash",
"computing",
"the",
"SHA",
"-",
"512",
"checksum",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/sha512/sha512.go#L128-L132 | train |
cloudflare/cfssl | scan/crypto/sha512/sha512.go | New384 | func New384() hash.Hash {
d := &digest{function: crypto.SHA384}
d.Reset()
return d
} | go | func New384() hash.Hash {
d := &digest{function: crypto.SHA384}
d.Reset()
return d
} | [
"func",
"New384",
"(",
")",
"hash",
".",
"Hash",
"{",
"d",
":=",
"&",
"digest",
"{",
"function",
":",
"crypto",
".",
"SHA384",
"}",
"\n",
"d",
".",
"Reset",
"(",
")",
"\n",
"return",
"d",
"\n",
"}"
] | // New384 returns a new hash.Hash computing the SHA-384 checksum. | [
"New384",
"returns",
"a",
"new",
"hash",
".",
"Hash",
"computing",
"the",
"SHA",
"-",
"384",
"checksum",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/sha512/sha512.go#L149-L153 | train |
cloudflare/cfssl | scan/crypto/sha512/sha512.go | Sum512 | func Sum512(data []byte) [Size]byte {
d := digest{function: crypto.SHA512}
d.Reset()
d.Write(data)
return d.checkSum()
} | go | func Sum512(data []byte) [Size]byte {
d := digest{function: crypto.SHA512}
d.Reset()
d.Write(data)
return d.checkSum()
} | [
"func",
"Sum512",
"(",
"data",
"[",
"]",
"byte",
")",
"[",
"Size",
"]",
"byte",
"{",
"d",
":=",
"digest",
"{",
"function",
":",
"crypto",
".",
"SHA512",
"}",
"\n",
"d",
".",
"Reset",
"(",
")",
"\n",
"d",
".",
"Write",
"(",
"data",
")",
"\n",
"return",
"d",
".",
"checkSum",
"(",
")",
"\n",
"}"
] | // Sum512 returns the SHA512 checksum of the data. | [
"Sum512",
"returns",
"the",
"SHA512",
"checksum",
"of",
"the",
"data",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/crypto/sha512/sha512.go#L253-L258 | train |
cloudflare/cfssl | api/ocsp/ocspsign.go | NewHandler | func NewHandler(s ocsp.Signer) http.Handler {
return &api.HTTPHandler{
Handler: &Handler{
signer: s,
},
Methods: []string{"POST"},
}
} | go | func NewHandler(s ocsp.Signer) http.Handler {
return &api.HTTPHandler{
Handler: &Handler{
signer: s,
},
Methods: []string{"POST"},
}
} | [
"func",
"NewHandler",
"(",
"s",
"ocsp",
".",
"Signer",
")",
"http",
".",
"Handler",
"{",
"return",
"&",
"api",
".",
"HTTPHandler",
"{",
"Handler",
":",
"&",
"Handler",
"{",
"signer",
":",
"s",
",",
"}",
",",
"Methods",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
"\n",
"}"
] | // NewHandler returns a new http.Handler that handles a ocspsign request. | [
"NewHandler",
"returns",
"a",
"new",
"http",
".",
"Handler",
"that",
"handles",
"a",
"ocspsign",
"request",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/ocsp/ocspsign.go#L28-L35 | train |
cloudflare/cfssl | api/ocsp/ocspsign.go | Handle | func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) error {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
r.Body.Close()
// Default the status to good so it matches the cli
req := &jsonSignRequest{
Status: "good",
}
err = json.Unmarshal(body, req)
if err != nil {
return errors.NewBadRequestString("Unable to parse sign request")
}
cert, err := helpers.ParseCertificatePEM([]byte(req.Certificate))
if err != nil {
log.Error("Error from ParseCertificatePEM", err)
return errors.NewBadRequestString("Malformed certificate")
}
signReq := ocsp.SignRequest{
Certificate: cert,
Status: req.Status,
}
// We need to convert the time from being a string to a time.Time
if req.Status == "revoked" {
signReq.Reason = req.Reason
// "now" is accepted and the default on the cli so default that here
if req.RevokedAt == "" || req.RevokedAt == "now" {
signReq.RevokedAt = time.Now()
} else {
signReq.RevokedAt, err = time.Parse("2006-01-02", req.RevokedAt)
if err != nil {
return errors.NewBadRequestString("Malformed revocation time")
}
}
}
if req.IssuerHash != "" {
issuerHash, ok := nameToHash[req.IssuerHash]
if !ok {
return errors.NewBadRequestString("Unsupported hash algorithm in request")
}
signReq.IssuerHash = issuerHash
}
resp, err := h.signer.Sign(signReq)
if err != nil {
return err
}
b64Resp := base64.StdEncoding.EncodeToString(resp)
result := map[string]string{"ocspResponse": b64Resp}
return api.SendResponse(w, result)
} | go | func (h *Handler) Handle(w http.ResponseWriter, r *http.Request) error {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
return err
}
r.Body.Close()
// Default the status to good so it matches the cli
req := &jsonSignRequest{
Status: "good",
}
err = json.Unmarshal(body, req)
if err != nil {
return errors.NewBadRequestString("Unable to parse sign request")
}
cert, err := helpers.ParseCertificatePEM([]byte(req.Certificate))
if err != nil {
log.Error("Error from ParseCertificatePEM", err)
return errors.NewBadRequestString("Malformed certificate")
}
signReq := ocsp.SignRequest{
Certificate: cert,
Status: req.Status,
}
// We need to convert the time from being a string to a time.Time
if req.Status == "revoked" {
signReq.Reason = req.Reason
// "now" is accepted and the default on the cli so default that here
if req.RevokedAt == "" || req.RevokedAt == "now" {
signReq.RevokedAt = time.Now()
} else {
signReq.RevokedAt, err = time.Parse("2006-01-02", req.RevokedAt)
if err != nil {
return errors.NewBadRequestString("Malformed revocation time")
}
}
}
if req.IssuerHash != "" {
issuerHash, ok := nameToHash[req.IssuerHash]
if !ok {
return errors.NewBadRequestString("Unsupported hash algorithm in request")
}
signReq.IssuerHash = issuerHash
}
resp, err := h.signer.Sign(signReq)
if err != nil {
return err
}
b64Resp := base64.StdEncoding.EncodeToString(resp)
result := map[string]string{"ocspResponse": b64Resp}
return api.SendResponse(w, result)
} | [
"func",
"(",
"h",
"*",
"Handler",
")",
"Handle",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"error",
"{",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"r",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n",
"r",
".",
"Body",
".",
"Close",
"(",
")",
"\n\n",
"// Default the status to good so it matches the cli",
"req",
":=",
"&",
"jsonSignRequest",
"{",
"Status",
":",
"\"",
"\"",
",",
"}",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"NewBadRequestString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"cert",
",",
"err",
":=",
"helpers",
".",
"ParseCertificatePEM",
"(",
"[",
"]",
"byte",
"(",
"req",
".",
"Certificate",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Error",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"errors",
".",
"NewBadRequestString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"signReq",
":=",
"ocsp",
".",
"SignRequest",
"{",
"Certificate",
":",
"cert",
",",
"Status",
":",
"req",
".",
"Status",
",",
"}",
"\n",
"// We need to convert the time from being a string to a time.Time",
"if",
"req",
".",
"Status",
"==",
"\"",
"\"",
"{",
"signReq",
".",
"Reason",
"=",
"req",
".",
"Reason",
"\n",
"// \"now\" is accepted and the default on the cli so default that here",
"if",
"req",
".",
"RevokedAt",
"==",
"\"",
"\"",
"||",
"req",
".",
"RevokedAt",
"==",
"\"",
"\"",
"{",
"signReq",
".",
"RevokedAt",
"=",
"time",
".",
"Now",
"(",
")",
"\n",
"}",
"else",
"{",
"signReq",
".",
"RevokedAt",
",",
"err",
"=",
"time",
".",
"Parse",
"(",
"\"",
"\"",
",",
"req",
".",
"RevokedAt",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"errors",
".",
"NewBadRequestString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"req",
".",
"IssuerHash",
"!=",
"\"",
"\"",
"{",
"issuerHash",
",",
"ok",
":=",
"nameToHash",
"[",
"req",
".",
"IssuerHash",
"]",
"\n",
"if",
"!",
"ok",
"{",
"return",
"errors",
".",
"NewBadRequestString",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n",
"signReq",
".",
"IssuerHash",
"=",
"issuerHash",
"\n",
"}",
"\n\n",
"resp",
",",
"err",
":=",
"h",
".",
"signer",
".",
"Sign",
"(",
"signReq",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"b64Resp",
":=",
"base64",
".",
"StdEncoding",
".",
"EncodeToString",
"(",
"resp",
")",
"\n",
"result",
":=",
"map",
"[",
"string",
"]",
"string",
"{",
"\"",
"\"",
":",
"b64Resp",
"}",
"\n",
"return",
"api",
".",
"SendResponse",
"(",
"w",
",",
"result",
")",
"\n",
"}"
] | // Handle responds to requests for a ocsp signature. It creates and signs
// a ocsp response for the provided certificate and status. If the status
// is revoked then it also adds reason and revoked_at. The response is
// base64 encoded. | [
"Handle",
"responds",
"to",
"requests",
"for",
"a",
"ocsp",
"signature",
".",
"It",
"creates",
"and",
"signs",
"a",
"ocsp",
"response",
"for",
"the",
"provided",
"certificate",
"and",
"status",
".",
"If",
"the",
"status",
"is",
"revoked",
"then",
"it",
"also",
"adds",
"reason",
"and",
"revoked_at",
".",
"The",
"response",
"is",
"base64",
"encoded",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/ocsp/ocspsign.go#L58-L113 | train |
cloudflare/cfssl | cmd/mkbundle/mkbundle.go | supervisor | func supervisor(paths chan string, bundler chan *x509.Certificate, numWorkers int) {
var workerPool sync.WaitGroup
for i := 0; i < numWorkers; i++ {
workerPool.Add(1)
go worker(paths, bundler, &workerPool)
}
workerPool.Wait()
close(bundler)
} | go | func supervisor(paths chan string, bundler chan *x509.Certificate, numWorkers int) {
var workerPool sync.WaitGroup
for i := 0; i < numWorkers; i++ {
workerPool.Add(1)
go worker(paths, bundler, &workerPool)
}
workerPool.Wait()
close(bundler)
} | [
"func",
"supervisor",
"(",
"paths",
"chan",
"string",
",",
"bundler",
"chan",
"*",
"x509",
".",
"Certificate",
",",
"numWorkers",
"int",
")",
"{",
"var",
"workerPool",
"sync",
".",
"WaitGroup",
"\n",
"for",
"i",
":=",
"0",
";",
"i",
"<",
"numWorkers",
";",
"i",
"++",
"{",
"workerPool",
".",
"Add",
"(",
"1",
")",
"\n",
"go",
"worker",
"(",
"paths",
",",
"bundler",
",",
"&",
"workerPool",
")",
"\n",
"}",
"\n",
"workerPool",
".",
"Wait",
"(",
")",
"\n",
"close",
"(",
"bundler",
")",
"\n",
"}"
] | // supervisor sets up the workers and signals the bundler that all
// certificates have been processed. | [
"supervisor",
"sets",
"up",
"the",
"workers",
"and",
"signals",
"the",
"bundler",
"that",
"all",
"certificates",
"have",
"been",
"processed",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/cmd/mkbundle/mkbundle.go#L76-L84 | train |
cloudflare/cfssl | cmd/mkbundle/mkbundle.go | makeBundle | func makeBundle(filename string, bundler chan *x509.Certificate) {
file, err := os.Create(filename)
if err != nil {
log.Errorf("%v", err)
return
}
defer file.Close()
var total int
for {
cert, ok := <-bundler
if !ok {
break
}
block := &pem.Block{
Type: "CERTIFICATE",
Bytes: cert.Raw,
}
err = pem.Encode(file, block)
if err != nil {
log.Errorf("Failed to write PEM block: %v", err)
break
}
total++
}
log.Infof("Wrote %d certificates.", total)
} | go | func makeBundle(filename string, bundler chan *x509.Certificate) {
file, err := os.Create(filename)
if err != nil {
log.Errorf("%v", err)
return
}
defer file.Close()
var total int
for {
cert, ok := <-bundler
if !ok {
break
}
block := &pem.Block{
Type: "CERTIFICATE",
Bytes: cert.Raw,
}
err = pem.Encode(file, block)
if err != nil {
log.Errorf("Failed to write PEM block: %v", err)
break
}
total++
}
log.Infof("Wrote %d certificates.", total)
} | [
"func",
"makeBundle",
"(",
"filename",
"string",
",",
"bundler",
"chan",
"*",
"x509",
".",
"Certificate",
")",
"{",
"file",
",",
"err",
":=",
"os",
".",
"Create",
"(",
"filename",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"\n",
"}",
"\n",
"defer",
"file",
".",
"Close",
"(",
")",
"\n\n",
"var",
"total",
"int",
"\n",
"for",
"{",
"cert",
",",
"ok",
":=",
"<-",
"bundler",
"\n",
"if",
"!",
"ok",
"{",
"break",
"\n",
"}",
"\n",
"block",
":=",
"&",
"pem",
".",
"Block",
"{",
"Type",
":",
"\"",
"\"",
",",
"Bytes",
":",
"cert",
".",
"Raw",
",",
"}",
"\n",
"err",
"=",
"pem",
".",
"Encode",
"(",
"file",
",",
"block",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"break",
"\n",
"}",
"\n",
"total",
"++",
"\n",
"}",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"total",
")",
"\n",
"}"
] | // makeBundle opens the file for writing, and listens for incoming
// certificates. These are PEM-encoded and written to file. | [
"makeBundle",
"opens",
"the",
"file",
"for",
"writing",
"and",
"listens",
"for",
"incoming",
"certificates",
".",
"These",
"are",
"PEM",
"-",
"encoded",
"and",
"written",
"to",
"file",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/cmd/mkbundle/mkbundle.go#L88-L114 | train |
cloudflare/cfssl | cmd/mkbundle/mkbundle.go | scanFiles | func scanFiles(paths chan string) {
walker := func(path string, info os.FileInfo, err error) error {
log.Infof("Found %s", path)
if err != nil {
return err
}
if info.Mode().IsRegular() {
paths <- path
}
return nil
}
for _, path := range flag.Args() {
err := filepath.Walk(path, walker)
if err != nil {
log.Errorf("Walk failed: %v", err)
}
}
close(paths)
} | go | func scanFiles(paths chan string) {
walker := func(path string, info os.FileInfo, err error) error {
log.Infof("Found %s", path)
if err != nil {
return err
}
if info.Mode().IsRegular() {
paths <- path
}
return nil
}
for _, path := range flag.Args() {
err := filepath.Walk(path, walker)
if err != nil {
log.Errorf("Walk failed: %v", err)
}
}
close(paths)
} | [
"func",
"scanFiles",
"(",
"paths",
"chan",
"string",
")",
"{",
"walker",
":=",
"func",
"(",
"path",
"string",
",",
"info",
"os",
".",
"FileInfo",
",",
"err",
"error",
")",
"error",
"{",
"log",
".",
"Infof",
"(",
"\"",
"\"",
",",
"path",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"err",
"\n",
"}",
"\n\n",
"if",
"info",
".",
"Mode",
"(",
")",
".",
"IsRegular",
"(",
")",
"{",
"paths",
"<-",
"path",
"\n",
"}",
"\n",
"return",
"nil",
"\n",
"}",
"\n\n",
"for",
"_",
",",
"path",
":=",
"range",
"flag",
".",
"Args",
"(",
")",
"{",
"err",
":=",
"filepath",
".",
"Walk",
"(",
"path",
",",
"walker",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"\n",
"}",
"\n",
"close",
"(",
"paths",
")",
"\n",
"}"
] | // scanFiles walks the files listed in the arguments. These files may
// be either certificate files or directories containing certificates. | [
"scanFiles",
"walks",
"the",
"files",
"listed",
"in",
"the",
"arguments",
".",
"These",
"files",
"may",
"be",
"either",
"certificate",
"files",
"or",
"directories",
"containing",
"certificates",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/cmd/mkbundle/mkbundle.go#L118-L138 | train |
cloudflare/cfssl | api/certadd/insert.go | NewHandler | func NewHandler(dbAccessor certdb.Accessor, signer ocsp.Signer) http.Handler {
return &api.HTTPHandler{
Handler: &Handler{
dbAccessor: dbAccessor,
signer: signer,
},
Methods: []string{"POST"},
}
} | go | func NewHandler(dbAccessor certdb.Accessor, signer ocsp.Signer) http.Handler {
return &api.HTTPHandler{
Handler: &Handler{
dbAccessor: dbAccessor,
signer: signer,
},
Methods: []string{"POST"},
}
} | [
"func",
"NewHandler",
"(",
"dbAccessor",
"certdb",
".",
"Accessor",
",",
"signer",
"ocsp",
".",
"Signer",
")",
"http",
".",
"Handler",
"{",
"return",
"&",
"api",
".",
"HTTPHandler",
"{",
"Handler",
":",
"&",
"Handler",
"{",
"dbAccessor",
":",
"dbAccessor",
",",
"signer",
":",
"signer",
",",
"}",
",",
"Methods",
":",
"[",
"]",
"string",
"{",
"\"",
"\"",
"}",
",",
"}",
"\n",
"}"
] | // NewHandler creates a new Handler from a certdb.Accessor and ocsp.Signer | [
"NewHandler",
"creates",
"a",
"new",
"Handler",
"from",
"a",
"certdb",
".",
"Accessor",
"and",
"ocsp",
".",
"Signer"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/certadd/insert.go#L38-L46 | train |
cloudflare/cfssl | scan/connectivity.go | dnsLookupScan | func dnsLookupScan(addr, hostname string) (grade Grade, output Output, err error) {
addrs, err := net.LookupHost(hostname)
if err != nil {
return
}
if len(addrs) == 0 {
err = errors.New("no addresses found for host")
}
grade, output = Good, addrs
return
} | go | func dnsLookupScan(addr, hostname string) (grade Grade, output Output, err error) {
addrs, err := net.LookupHost(hostname)
if err != nil {
return
}
if len(addrs) == 0 {
err = errors.New("no addresses found for host")
}
grade, output = Good, addrs
return
} | [
"func",
"dnsLookupScan",
"(",
"addr",
",",
"hostname",
"string",
")",
"(",
"grade",
"Grade",
",",
"output",
"Output",
",",
"err",
"error",
")",
"{",
"addrs",
",",
"err",
":=",
"net",
".",
"LookupHost",
"(",
"hostname",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n\n",
"if",
"len",
"(",
"addrs",
")",
"==",
"0",
"{",
"err",
"=",
"errors",
".",
"New",
"(",
"\"",
"\"",
")",
"\n",
"}",
"\n\n",
"grade",
",",
"output",
"=",
"Good",
",",
"addrs",
"\n",
"return",
"\n",
"}"
] | // dnsLookupScan tests that DNS resolution of the host returns at least one address | [
"dnsLookupScan",
"tests",
"that",
"DNS",
"resolution",
"of",
"the",
"host",
"returns",
"at",
"least",
"one",
"address"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/connectivity.go#L37-L49 | train |
cloudflare/cfssl | scan/connectivity.go | tcpDialScan | func tcpDialScan(addr, hostname string) (grade Grade, output Output, err error) {
conn, err := Dialer.Dial(Network, addr)
if err != nil {
return
}
conn.Close()
grade = Good
return
} | go | func tcpDialScan(addr, hostname string) (grade Grade, output Output, err error) {
conn, err := Dialer.Dial(Network, addr)
if err != nil {
return
}
conn.Close()
grade = Good
return
} | [
"func",
"tcpDialScan",
"(",
"addr",
",",
"hostname",
"string",
")",
"(",
"grade",
"Grade",
",",
"output",
"Output",
",",
"err",
"error",
")",
"{",
"conn",
",",
"err",
":=",
"Dialer",
".",
"Dial",
"(",
"Network",
",",
"addr",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"conn",
".",
"Close",
"(",
")",
"\n",
"grade",
"=",
"Good",
"\n",
"return",
"\n",
"}"
] | // tcpDialScan tests that the host can be connected to through TCP. | [
"tcpDialScan",
"tests",
"that",
"the",
"host",
"can",
"be",
"connected",
"to",
"through",
"TCP",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/connectivity.go#L132-L140 | train |
cloudflare/cfssl | scan/connectivity.go | tlsDialScan | func tlsDialScan(addr, hostname string) (grade Grade, output Output, err error) {
var conn *tls.Conn
config := defaultTLSConfig(hostname)
if conn, err = tls.DialWithDialer(Dialer, Network, addr, config); err != nil {
return
}
conn.Close()
config.InsecureSkipVerify = false
if conn, err = tls.DialWithDialer(Dialer, Network, addr, config); err != nil {
grade = Warning
return
}
conn.Close()
grade = Good
return
} | go | func tlsDialScan(addr, hostname string) (grade Grade, output Output, err error) {
var conn *tls.Conn
config := defaultTLSConfig(hostname)
if conn, err = tls.DialWithDialer(Dialer, Network, addr, config); err != nil {
return
}
conn.Close()
config.InsecureSkipVerify = false
if conn, err = tls.DialWithDialer(Dialer, Network, addr, config); err != nil {
grade = Warning
return
}
conn.Close()
grade = Good
return
} | [
"func",
"tlsDialScan",
"(",
"addr",
",",
"hostname",
"string",
")",
"(",
"grade",
"Grade",
",",
"output",
"Output",
",",
"err",
"error",
")",
"{",
"var",
"conn",
"*",
"tls",
".",
"Conn",
"\n",
"config",
":=",
"defaultTLSConfig",
"(",
"hostname",
")",
"\n\n",
"if",
"conn",
",",
"err",
"=",
"tls",
".",
"DialWithDialer",
"(",
"Dialer",
",",
"Network",
",",
"addr",
",",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"return",
"\n",
"}",
"\n",
"conn",
".",
"Close",
"(",
")",
"\n\n",
"config",
".",
"InsecureSkipVerify",
"=",
"false",
"\n",
"if",
"conn",
",",
"err",
"=",
"tls",
".",
"DialWithDialer",
"(",
"Dialer",
",",
"Network",
",",
"addr",
",",
"config",
")",
";",
"err",
"!=",
"nil",
"{",
"grade",
"=",
"Warning",
"\n",
"return",
"\n",
"}",
"\n",
"conn",
".",
"Close",
"(",
")",
"\n\n",
"grade",
"=",
"Good",
"\n",
"return",
"\n",
"}"
] | // tlsDialScan tests that the host can perform a TLS Handshake
// and warns if the server's certificate can't be verified. | [
"tlsDialScan",
"tests",
"that",
"the",
"host",
"can",
"perform",
"a",
"TLS",
"Handshake",
"and",
"warns",
"if",
"the",
"server",
"s",
"certificate",
"can",
"t",
"be",
"verified",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/scan/connectivity.go#L144-L162 | train |
cloudflare/cfssl | api/api.go | HandleError | func HandleError(w http.ResponseWriter, err error) (code int) {
if err == nil {
return http.StatusOK
}
msg := err.Error()
httpCode := http.StatusInternalServerError
// If it is recognized as HttpError emitted from cfssl,
// we rewrite the status code accordingly. If it is a
// cfssl error, set the http status to StatusBadRequest
switch err := err.(type) {
case *errors.HTTPError:
httpCode = err.StatusCode
code = err.StatusCode
case *errors.Error:
httpCode = http.StatusBadRequest
code = err.ErrorCode
msg = err.Message
}
response := NewErrorResponse(msg, code)
jsonMessage, err := json.Marshal(response)
if err != nil {
log.Errorf("Failed to marshal JSON: %v", err)
} else {
msg = string(jsonMessage)
}
http.Error(w, msg, httpCode)
return code
} | go | func HandleError(w http.ResponseWriter, err error) (code int) {
if err == nil {
return http.StatusOK
}
msg := err.Error()
httpCode := http.StatusInternalServerError
// If it is recognized as HttpError emitted from cfssl,
// we rewrite the status code accordingly. If it is a
// cfssl error, set the http status to StatusBadRequest
switch err := err.(type) {
case *errors.HTTPError:
httpCode = err.StatusCode
code = err.StatusCode
case *errors.Error:
httpCode = http.StatusBadRequest
code = err.ErrorCode
msg = err.Message
}
response := NewErrorResponse(msg, code)
jsonMessage, err := json.Marshal(response)
if err != nil {
log.Errorf("Failed to marshal JSON: %v", err)
} else {
msg = string(jsonMessage)
}
http.Error(w, msg, httpCode)
return code
} | [
"func",
"HandleError",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"err",
"error",
")",
"(",
"code",
"int",
")",
"{",
"if",
"err",
"==",
"nil",
"{",
"return",
"http",
".",
"StatusOK",
"\n",
"}",
"\n",
"msg",
":=",
"err",
".",
"Error",
"(",
")",
"\n",
"httpCode",
":=",
"http",
".",
"StatusInternalServerError",
"\n\n",
"// If it is recognized as HttpError emitted from cfssl,",
"// we rewrite the status code accordingly. If it is a",
"// cfssl error, set the http status to StatusBadRequest",
"switch",
"err",
":=",
"err",
".",
"(",
"type",
")",
"{",
"case",
"*",
"errors",
".",
"HTTPError",
":",
"httpCode",
"=",
"err",
".",
"StatusCode",
"\n",
"code",
"=",
"err",
".",
"StatusCode",
"\n",
"case",
"*",
"errors",
".",
"Error",
":",
"httpCode",
"=",
"http",
".",
"StatusBadRequest",
"\n",
"code",
"=",
"err",
".",
"ErrorCode",
"\n",
"msg",
"=",
"err",
".",
"Message",
"\n",
"}",
"\n\n",
"response",
":=",
"NewErrorResponse",
"(",
"msg",
",",
"code",
")",
"\n",
"jsonMessage",
",",
"err",
":=",
"json",
".",
"Marshal",
"(",
"response",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"}",
"else",
"{",
"msg",
"=",
"string",
"(",
"jsonMessage",
")",
"\n",
"}",
"\n",
"http",
".",
"Error",
"(",
"w",
",",
"msg",
",",
"httpCode",
")",
"\n",
"return",
"code",
"\n",
"}"
] | // HandleError is the centralised error handling and reporting. | [
"HandleError",
"is",
"the",
"centralised",
"error",
"handling",
"and",
"reporting",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/api.go#L38-L67 | train |
cloudflare/cfssl | api/api.go | ServeHTTP | func (h HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var err error
var match bool
// Throw 405 when requested with an unsupported verb.
for _, m := range h.Methods {
if m == r.Method {
match = true
}
}
if match {
err = h.Handle(w, r)
} else {
err = errors.NewMethodNotAllowed(r.Method)
}
status := HandleError(w, err)
log.Infof("%s - \"%s %s\" %d", r.RemoteAddr, r.Method, r.URL, status)
} | go | func (h HTTPHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var err error
var match bool
// Throw 405 when requested with an unsupported verb.
for _, m := range h.Methods {
if m == r.Method {
match = true
}
}
if match {
err = h.Handle(w, r)
} else {
err = errors.NewMethodNotAllowed(r.Method)
}
status := HandleError(w, err)
log.Infof("%s - \"%s %s\" %d", r.RemoteAddr, r.Method, r.URL, status)
} | [
"func",
"(",
"h",
"HTTPHandler",
")",
"ServeHTTP",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"r",
"*",
"http",
".",
"Request",
")",
"{",
"var",
"err",
"error",
"\n",
"var",
"match",
"bool",
"\n",
"// Throw 405 when requested with an unsupported verb.",
"for",
"_",
",",
"m",
":=",
"range",
"h",
".",
"Methods",
"{",
"if",
"m",
"==",
"r",
".",
"Method",
"{",
"match",
"=",
"true",
"\n",
"}",
"\n",
"}",
"\n",
"if",
"match",
"{",
"err",
"=",
"h",
".",
"Handle",
"(",
"w",
",",
"r",
")",
"\n",
"}",
"else",
"{",
"err",
"=",
"errors",
".",
"NewMethodNotAllowed",
"(",
"r",
".",
"Method",
")",
"\n",
"}",
"\n",
"status",
":=",
"HandleError",
"(",
"w",
",",
"err",
")",
"\n",
"log",
".",
"Infof",
"(",
"\"",
"\\\"",
"\\\"",
"\"",
",",
"r",
".",
"RemoteAddr",
",",
"r",
".",
"Method",
",",
"r",
".",
"URL",
",",
"status",
")",
"\n",
"}"
] | // ServeHTTP encapsulates the call to underlying Handler to handle the request
// and return the response with proper HTTP status code | [
"ServeHTTP",
"encapsulates",
"the",
"call",
"to",
"underlying",
"Handler",
"to",
"handle",
"the",
"request",
"and",
"return",
"the",
"response",
"with",
"proper",
"HTTP",
"status",
"code"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/api.go#L71-L87 | train |
cloudflare/cfssl | api/api.go | NewSuccessResponse | func NewSuccessResponse(result interface{}) Response {
return Response{
Success: true,
Result: result,
Errors: []ResponseMessage{},
Messages: []ResponseMessage{},
}
} | go | func NewSuccessResponse(result interface{}) Response {
return Response{
Success: true,
Result: result,
Errors: []ResponseMessage{},
Messages: []ResponseMessage{},
}
} | [
"func",
"NewSuccessResponse",
"(",
"result",
"interface",
"{",
"}",
")",
"Response",
"{",
"return",
"Response",
"{",
"Success",
":",
"true",
",",
"Result",
":",
"result",
",",
"Errors",
":",
"[",
"]",
"ResponseMessage",
"{",
"}",
",",
"Messages",
":",
"[",
"]",
"ResponseMessage",
"{",
"}",
",",
"}",
"\n",
"}"
] | // NewSuccessResponse is a shortcut for creating new successul API
// responses. | [
"NewSuccessResponse",
"is",
"a",
"shortcut",
"for",
"creating",
"new",
"successul",
"API",
"responses",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/api.go#L181-L188 | train |
cloudflare/cfssl | api/api.go | NewSuccessResponseWithMessage | func NewSuccessResponseWithMessage(result interface{}, message string, code int) Response {
return Response{
Success: true,
Result: result,
Errors: []ResponseMessage{},
Messages: []ResponseMessage{{code, message}},
}
} | go | func NewSuccessResponseWithMessage(result interface{}, message string, code int) Response {
return Response{
Success: true,
Result: result,
Errors: []ResponseMessage{},
Messages: []ResponseMessage{{code, message}},
}
} | [
"func",
"NewSuccessResponseWithMessage",
"(",
"result",
"interface",
"{",
"}",
",",
"message",
"string",
",",
"code",
"int",
")",
"Response",
"{",
"return",
"Response",
"{",
"Success",
":",
"true",
",",
"Result",
":",
"result",
",",
"Errors",
":",
"[",
"]",
"ResponseMessage",
"{",
"}",
",",
"Messages",
":",
"[",
"]",
"ResponseMessage",
"{",
"{",
"code",
",",
"message",
"}",
"}",
",",
"}",
"\n",
"}"
] | // NewSuccessResponseWithMessage is a shortcut for creating new successul API
// responses that includes a message. | [
"NewSuccessResponseWithMessage",
"is",
"a",
"shortcut",
"for",
"creating",
"new",
"successul",
"API",
"responses",
"that",
"includes",
"a",
"message",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/api.go#L192-L199 | train |
cloudflare/cfssl | api/api.go | NewErrorResponse | func NewErrorResponse(message string, code int) Response {
return Response{
Success: false,
Result: nil,
Errors: []ResponseMessage{{code, message}},
Messages: []ResponseMessage{},
}
} | go | func NewErrorResponse(message string, code int) Response {
return Response{
Success: false,
Result: nil,
Errors: []ResponseMessage{{code, message}},
Messages: []ResponseMessage{},
}
} | [
"func",
"NewErrorResponse",
"(",
"message",
"string",
",",
"code",
"int",
")",
"Response",
"{",
"return",
"Response",
"{",
"Success",
":",
"false",
",",
"Result",
":",
"nil",
",",
"Errors",
":",
"[",
"]",
"ResponseMessage",
"{",
"{",
"code",
",",
"message",
"}",
"}",
",",
"Messages",
":",
"[",
"]",
"ResponseMessage",
"{",
"}",
",",
"}",
"\n",
"}"
] | // NewErrorResponse is a shortcut for creating an error response for a
// single error. | [
"NewErrorResponse",
"is",
"a",
"shortcut",
"for",
"creating",
"an",
"error",
"response",
"for",
"a",
"single",
"error",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/api.go#L203-L210 | train |
cloudflare/cfssl | api/api.go | SendResponse | func SendResponse(w http.ResponseWriter, result interface{}) error {
response := NewSuccessResponse(result)
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
err := enc.Encode(response)
return err
} | go | func SendResponse(w http.ResponseWriter, result interface{}) error {
response := NewSuccessResponse(result)
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
err := enc.Encode(response)
return err
} | [
"func",
"SendResponse",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"result",
"interface",
"{",
"}",
")",
"error",
"{",
"response",
":=",
"NewSuccessResponse",
"(",
"result",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"err",
":=",
"enc",
".",
"Encode",
"(",
"response",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // SendResponse builds a response from the result, sets the JSON
// header, and writes to the http.ResponseWriter. | [
"SendResponse",
"builds",
"a",
"response",
"from",
"the",
"result",
"sets",
"the",
"JSON",
"header",
"and",
"writes",
"to",
"the",
"http",
".",
"ResponseWriter",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/api.go#L214-L220 | train |
cloudflare/cfssl | api/api.go | SendResponseWithMessage | func SendResponseWithMessage(w http.ResponseWriter, result interface{}, message string, code int) error {
response := NewSuccessResponseWithMessage(result, message, code)
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
err := enc.Encode(response)
return err
} | go | func SendResponseWithMessage(w http.ResponseWriter, result interface{}, message string, code int) error {
response := NewSuccessResponseWithMessage(result, message, code)
w.Header().Set("Content-Type", "application/json")
enc := json.NewEncoder(w)
err := enc.Encode(response)
return err
} | [
"func",
"SendResponseWithMessage",
"(",
"w",
"http",
".",
"ResponseWriter",
",",
"result",
"interface",
"{",
"}",
",",
"message",
"string",
",",
"code",
"int",
")",
"error",
"{",
"response",
":=",
"NewSuccessResponseWithMessage",
"(",
"result",
",",
"message",
",",
"code",
")",
"\n",
"w",
".",
"Header",
"(",
")",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"enc",
":=",
"json",
".",
"NewEncoder",
"(",
"w",
")",
"\n",
"err",
":=",
"enc",
".",
"Encode",
"(",
"response",
")",
"\n",
"return",
"err",
"\n",
"}"
] | // SendResponseWithMessage builds a response from the result and the
// provided message, sets the JSON header, and writes to the
// http.ResponseWriter. | [
"SendResponseWithMessage",
"builds",
"a",
"response",
"from",
"the",
"result",
"and",
"the",
"provided",
"message",
"sets",
"the",
"JSON",
"header",
"and",
"writes",
"to",
"the",
"http",
".",
"ResponseWriter",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/api.go#L225-L231 | train |
cloudflare/cfssl | api/client/client.go | NewServerTLS | func NewServerTLS(addr string, tlsConfig *tls.Config) Remote {
addrs := strings.Split(addr, ",")
var remote Remote
if len(addrs) > 1 {
remote, _ = NewGroup(addrs, tlsConfig, StrategyOrderedList)
} else {
u, err := normalizeURL(addrs[0])
if err != nil {
log.Errorf("bad url: %v", err)
return nil
}
srv := newServer(u, tlsConfig)
if srv != nil {
remote = srv
}
}
return remote
} | go | func NewServerTLS(addr string, tlsConfig *tls.Config) Remote {
addrs := strings.Split(addr, ",")
var remote Remote
if len(addrs) > 1 {
remote, _ = NewGroup(addrs, tlsConfig, StrategyOrderedList)
} else {
u, err := normalizeURL(addrs[0])
if err != nil {
log.Errorf("bad url: %v", err)
return nil
}
srv := newServer(u, tlsConfig)
if srv != nil {
remote = srv
}
}
return remote
} | [
"func",
"NewServerTLS",
"(",
"addr",
"string",
",",
"tlsConfig",
"*",
"tls",
".",
"Config",
")",
"Remote",
"{",
"addrs",
":=",
"strings",
".",
"Split",
"(",
"addr",
",",
"\"",
"\"",
")",
"\n\n",
"var",
"remote",
"Remote",
"\n\n",
"if",
"len",
"(",
"addrs",
")",
">",
"1",
"{",
"remote",
",",
"_",
"=",
"NewGroup",
"(",
"addrs",
",",
"tlsConfig",
",",
"StrategyOrderedList",
")",
"\n",
"}",
"else",
"{",
"u",
",",
"err",
":=",
"normalizeURL",
"(",
"addrs",
"[",
"0",
"]",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"err",
")",
"\n",
"return",
"nil",
"\n",
"}",
"\n",
"srv",
":=",
"newServer",
"(",
"u",
",",
"tlsConfig",
")",
"\n",
"if",
"srv",
"!=",
"nil",
"{",
"remote",
"=",
"srv",
"\n",
"}",
"\n",
"}",
"\n",
"return",
"remote",
"\n",
"}"
] | // NewServerTLS is the TLS version of NewServer | [
"NewServerTLS",
"is",
"the",
"TLS",
"version",
"of",
"NewServer"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/client/client.go#L59-L78 | train |
cloudflare/cfssl | api/client/client.go | post | func (srv *server) post(url string, jsonData []byte) (*api.Response, error) {
var resp *http.Response
var err error
client := &http.Client{}
if srv.TLSConfig != nil {
client.Transport = srv.createTransport()
}
if srv.RequestTimeout != 0 {
client.Timeout = srv.RequestTimeout
}
req, err := http.NewRequest("POST", url, bytes.NewReader(jsonData))
if err != nil {
err = fmt.Errorf("failed POST to %s: %v", url, err)
return nil, errors.Wrap(errors.APIClientError, errors.ClientHTTPError, err)
}
req.Close = true
req.Header.Set("content-type", "application/json")
if srv.reqModifier != nil {
srv.reqModifier(req, jsonData)
}
resp, err = client.Do(req)
if err != nil {
err = fmt.Errorf("failed POST to %s: %v", url, err)
return nil, errors.Wrap(errors.APIClientError, errors.ClientHTTPError, err)
}
defer req.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrap(errors.APIClientError, errors.IOError, err)
}
if resp.StatusCode != http.StatusOK {
log.Errorf("http error with %s", url)
return nil, errors.Wrap(errors.APIClientError, errors.ClientHTTPError, stderr.New(string(body)))
}
var response api.Response
err = json.Unmarshal(body, &response)
if err != nil {
log.Debug("Unable to parse response body:", string(body))
return nil, errors.Wrap(errors.APIClientError, errors.JSONError, err)
}
if !response.Success || response.Result == nil {
if len(response.Errors) > 0 {
return nil, errors.Wrap(errors.APIClientError, errors.ServerRequestFailed, stderr.New(response.Errors[0].Message))
}
return nil, errors.New(errors.APIClientError, errors.ServerRequestFailed)
}
return &response, nil
} | go | func (srv *server) post(url string, jsonData []byte) (*api.Response, error) {
var resp *http.Response
var err error
client := &http.Client{}
if srv.TLSConfig != nil {
client.Transport = srv.createTransport()
}
if srv.RequestTimeout != 0 {
client.Timeout = srv.RequestTimeout
}
req, err := http.NewRequest("POST", url, bytes.NewReader(jsonData))
if err != nil {
err = fmt.Errorf("failed POST to %s: %v", url, err)
return nil, errors.Wrap(errors.APIClientError, errors.ClientHTTPError, err)
}
req.Close = true
req.Header.Set("content-type", "application/json")
if srv.reqModifier != nil {
srv.reqModifier(req, jsonData)
}
resp, err = client.Do(req)
if err != nil {
err = fmt.Errorf("failed POST to %s: %v", url, err)
return nil, errors.Wrap(errors.APIClientError, errors.ClientHTTPError, err)
}
defer req.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrap(errors.APIClientError, errors.IOError, err)
}
if resp.StatusCode != http.StatusOK {
log.Errorf("http error with %s", url)
return nil, errors.Wrap(errors.APIClientError, errors.ClientHTTPError, stderr.New(string(body)))
}
var response api.Response
err = json.Unmarshal(body, &response)
if err != nil {
log.Debug("Unable to parse response body:", string(body))
return nil, errors.Wrap(errors.APIClientError, errors.JSONError, err)
}
if !response.Success || response.Result == nil {
if len(response.Errors) > 0 {
return nil, errors.Wrap(errors.APIClientError, errors.ServerRequestFailed, stderr.New(response.Errors[0].Message))
}
return nil, errors.New(errors.APIClientError, errors.ServerRequestFailed)
}
return &response, nil
} | [
"func",
"(",
"srv",
"*",
"server",
")",
"post",
"(",
"url",
"string",
",",
"jsonData",
"[",
"]",
"byte",
")",
"(",
"*",
"api",
".",
"Response",
",",
"error",
")",
"{",
"var",
"resp",
"*",
"http",
".",
"Response",
"\n",
"var",
"err",
"error",
"\n",
"client",
":=",
"&",
"http",
".",
"Client",
"{",
"}",
"\n",
"if",
"srv",
".",
"TLSConfig",
"!=",
"nil",
"{",
"client",
".",
"Transport",
"=",
"srv",
".",
"createTransport",
"(",
")",
"\n",
"}",
"\n",
"if",
"srv",
".",
"RequestTimeout",
"!=",
"0",
"{",
"client",
".",
"Timeout",
"=",
"srv",
".",
"RequestTimeout",
"\n",
"}",
"\n",
"req",
",",
"err",
":=",
"http",
".",
"NewRequest",
"(",
"\"",
"\"",
",",
"url",
",",
"bytes",
".",
"NewReader",
"(",
"jsonData",
")",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"url",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"errors",
".",
"APIClientError",
",",
"errors",
".",
"ClientHTTPError",
",",
"err",
")",
"\n",
"}",
"\n",
"req",
".",
"Close",
"=",
"true",
"\n",
"req",
".",
"Header",
".",
"Set",
"(",
"\"",
"\"",
",",
"\"",
"\"",
")",
"\n",
"if",
"srv",
".",
"reqModifier",
"!=",
"nil",
"{",
"srv",
".",
"reqModifier",
"(",
"req",
",",
"jsonData",
")",
"\n",
"}",
"\n",
"resp",
",",
"err",
"=",
"client",
".",
"Do",
"(",
"req",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"err",
"=",
"fmt",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"url",
",",
"err",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"errors",
".",
"APIClientError",
",",
"errors",
".",
"ClientHTTPError",
",",
"err",
")",
"\n",
"}",
"\n",
"defer",
"req",
".",
"Body",
".",
"Close",
"(",
")",
"\n",
"body",
",",
"err",
":=",
"ioutil",
".",
"ReadAll",
"(",
"resp",
".",
"Body",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"errors",
".",
"APIClientError",
",",
"errors",
".",
"IOError",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"resp",
".",
"StatusCode",
"!=",
"http",
".",
"StatusOK",
"{",
"log",
".",
"Errorf",
"(",
"\"",
"\"",
",",
"url",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"errors",
".",
"APIClientError",
",",
"errors",
".",
"ClientHTTPError",
",",
"stderr",
".",
"New",
"(",
"string",
"(",
"body",
")",
")",
")",
"\n",
"}",
"\n\n",
"var",
"response",
"api",
".",
"Response",
"\n",
"err",
"=",
"json",
".",
"Unmarshal",
"(",
"body",
",",
"&",
"response",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"log",
".",
"Debug",
"(",
"\"",
"\"",
",",
"string",
"(",
"body",
")",
")",
"\n",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"errors",
".",
"APIClientError",
",",
"errors",
".",
"JSONError",
",",
"err",
")",
"\n",
"}",
"\n\n",
"if",
"!",
"response",
".",
"Success",
"||",
"response",
".",
"Result",
"==",
"nil",
"{",
"if",
"len",
"(",
"response",
".",
"Errors",
")",
">",
"0",
"{",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"errors",
".",
"APIClientError",
",",
"errors",
".",
"ServerRequestFailed",
",",
"stderr",
".",
"New",
"(",
"response",
".",
"Errors",
"[",
"0",
"]",
".",
"Message",
")",
")",
"\n",
"}",
"\n",
"return",
"nil",
",",
"errors",
".",
"New",
"(",
"errors",
".",
"APIClientError",
",",
"errors",
".",
"ServerRequestFailed",
")",
"\n",
"}",
"\n\n",
"return",
"&",
"response",
",",
"nil",
"\n",
"}"
] | // post connects to the remote server and returns a Response struct | [
"post",
"connects",
"to",
"the",
"remote",
"server",
"and",
"returns",
"a",
"Response",
"struct"
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/client/client.go#L134-L185 | train |
cloudflare/cfssl | api/client/client.go | AuthSign | func (srv *server) AuthSign(req, id []byte, provider auth.Provider) ([]byte, error) {
return srv.authReq(req, id, provider, "sign")
} | go | func (srv *server) AuthSign(req, id []byte, provider auth.Provider) ([]byte, error) {
return srv.authReq(req, id, provider, "sign")
} | [
"func",
"(",
"srv",
"*",
"server",
")",
"AuthSign",
"(",
"req",
",",
"id",
"[",
"]",
"byte",
",",
"provider",
"auth",
".",
"Provider",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"srv",
".",
"authReq",
"(",
"req",
",",
"id",
",",
"provider",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // AuthSign fills out an authenticated signing request to the server,
// receiving a certificate or error in response.
// It takes the serialized JSON request to send, remote address and
// authentication provider. | [
"AuthSign",
"fills",
"out",
"an",
"authenticated",
"signing",
"request",
"to",
"the",
"server",
"receiving",
"a",
"certificate",
"or",
"error",
"in",
"response",
".",
"It",
"takes",
"the",
"serialized",
"JSON",
"request",
"to",
"send",
"remote",
"address",
"and",
"authentication",
"provider",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/client/client.go#L191-L193 | train |
cloudflare/cfssl | api/client/client.go | Sign | func (srv *server) Sign(jsonData []byte) ([]byte, error) {
return srv.request(jsonData, "sign")
} | go | func (srv *server) Sign(jsonData []byte) ([]byte, error) {
return srv.request(jsonData, "sign")
} | [
"func",
"(",
"srv",
"*",
"server",
")",
"Sign",
"(",
"jsonData",
"[",
"]",
"byte",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"return",
"srv",
".",
"request",
"(",
"jsonData",
",",
"\"",
"\"",
")",
"\n",
"}"
] | // Sign sends a signature request to the remote CFSSL server,
// receiving a signed certificate or an error in response.
// It takes the serialized JSON request to send. | [
"Sign",
"sends",
"a",
"signature",
"request",
"to",
"the",
"remote",
"CFSSL",
"server",
"receiving",
"a",
"signed",
"certificate",
"or",
"an",
"error",
"in",
"response",
".",
"It",
"takes",
"the",
"serialized",
"JSON",
"request",
"to",
"send",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/client/client.go#L247-L249 | train |
cloudflare/cfssl | api/client/client.go | Info | func (srv *server) Info(jsonData []byte) (*info.Resp, error) {
res, err := srv.getResultMap(jsonData, "info")
if err != nil {
return nil, err
}
info := new(info.Resp)
if val, ok := res["certificate"]; ok {
info.Certificate = val.(string)
}
var usages []interface{}
if val, ok := res["usages"]; ok && val != nil {
usages = val.([]interface{})
}
if val, ok := res["expiry"]; ok && val != nil {
info.ExpiryString = val.(string)
}
info.Usage = make([]string, len(usages))
for i, s := range usages {
info.Usage[i] = s.(string)
}
return info, nil
} | go | func (srv *server) Info(jsonData []byte) (*info.Resp, error) {
res, err := srv.getResultMap(jsonData, "info")
if err != nil {
return nil, err
}
info := new(info.Resp)
if val, ok := res["certificate"]; ok {
info.Certificate = val.(string)
}
var usages []interface{}
if val, ok := res["usages"]; ok && val != nil {
usages = val.([]interface{})
}
if val, ok := res["expiry"]; ok && val != nil {
info.ExpiryString = val.(string)
}
info.Usage = make([]string, len(usages))
for i, s := range usages {
info.Usage[i] = s.(string)
}
return info, nil
} | [
"func",
"(",
"srv",
"*",
"server",
")",
"Info",
"(",
"jsonData",
"[",
"]",
"byte",
")",
"(",
"*",
"info",
".",
"Resp",
",",
"error",
")",
"{",
"res",
",",
"err",
":=",
"srv",
".",
"getResultMap",
"(",
"jsonData",
",",
"\"",
"\"",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n\n",
"info",
":=",
"new",
"(",
"info",
".",
"Resp",
")",
"\n\n",
"if",
"val",
",",
"ok",
":=",
"res",
"[",
"\"",
"\"",
"]",
";",
"ok",
"{",
"info",
".",
"Certificate",
"=",
"val",
".",
"(",
"string",
")",
"\n",
"}",
"\n",
"var",
"usages",
"[",
"]",
"interface",
"{",
"}",
"\n",
"if",
"val",
",",
"ok",
":=",
"res",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"val",
"!=",
"nil",
"{",
"usages",
"=",
"val",
".",
"(",
"[",
"]",
"interface",
"{",
"}",
")",
"\n",
"}",
"\n",
"if",
"val",
",",
"ok",
":=",
"res",
"[",
"\"",
"\"",
"]",
";",
"ok",
"&&",
"val",
"!=",
"nil",
"{",
"info",
".",
"ExpiryString",
"=",
"val",
".",
"(",
"string",
")",
"\n",
"}",
"\n\n",
"info",
".",
"Usage",
"=",
"make",
"(",
"[",
"]",
"string",
",",
"len",
"(",
"usages",
")",
")",
"\n",
"for",
"i",
",",
"s",
":=",
"range",
"usages",
"{",
"info",
".",
"Usage",
"[",
"i",
"]",
"=",
"s",
".",
"(",
"string",
")",
"\n",
"}",
"\n\n",
"return",
"info",
",",
"nil",
"\n",
"}"
] | // Info sends an info request to the remote CFSSL server, receiving a
// response or an error in response.
// It takes the serialized JSON request to send. | [
"Info",
"sends",
"an",
"info",
"request",
"to",
"the",
"remote",
"CFSSL",
"server",
"receiving",
"a",
"response",
"or",
"an",
"error",
"in",
"response",
".",
"It",
"takes",
"the",
"serialized",
"JSON",
"request",
"to",
"send",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/client/client.go#L254-L279 | train |
cloudflare/cfssl | api/client/client.go | request | func (srv *server) request(jsonData []byte, target string) ([]byte, error) {
result, err := srv.getResultMap(jsonData, target)
if err != nil {
return nil, err
}
cert := result["certificate"].(string)
if cert != "" {
return []byte(cert), nil
}
return nil, errors.Wrap(errors.APIClientError, errors.ClientHTTPError, stderr.New("response doesn't contain certificate."))
} | go | func (srv *server) request(jsonData []byte, target string) ([]byte, error) {
result, err := srv.getResultMap(jsonData, target)
if err != nil {
return nil, err
}
cert := result["certificate"].(string)
if cert != "" {
return []byte(cert), nil
}
return nil, errors.Wrap(errors.APIClientError, errors.ClientHTTPError, stderr.New("response doesn't contain certificate."))
} | [
"func",
"(",
"srv",
"*",
"server",
")",
"request",
"(",
"jsonData",
"[",
"]",
"byte",
",",
"target",
"string",
")",
"(",
"[",
"]",
"byte",
",",
"error",
")",
"{",
"result",
",",
"err",
":=",
"srv",
".",
"getResultMap",
"(",
"jsonData",
",",
"target",
")",
"\n",
"if",
"err",
"!=",
"nil",
"{",
"return",
"nil",
",",
"err",
"\n",
"}",
"\n",
"cert",
":=",
"result",
"[",
"\"",
"\"",
"]",
".",
"(",
"string",
")",
"\n",
"if",
"cert",
"!=",
"\"",
"\"",
"{",
"return",
"[",
"]",
"byte",
"(",
"cert",
")",
",",
"nil",
"\n",
"}",
"\n\n",
"return",
"nil",
",",
"errors",
".",
"Wrap",
"(",
"errors",
".",
"APIClientError",
",",
"errors",
".",
"ClientHTTPError",
",",
"stderr",
".",
"New",
"(",
"\"",
"\"",
")",
")",
"\n",
"}"
] | // request performs the common logic for Sign and Info, performing the actual
// request and returning the resultant certificate. | [
"request",
"performs",
"the",
"common",
"logic",
"for",
"Sign",
"and",
"Info",
"performing",
"the",
"actual",
"request",
"and",
"returning",
"the",
"resultant",
"certificate",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/client/client.go#L297-L308 | train |
cloudflare/cfssl | api/client/client.go | NewAuthServer | func NewAuthServer(addr string, tlsConfig *tls.Config, provider auth.Provider) *AuthRemote {
return &AuthRemote{
Remote: NewServerTLS(addr, tlsConfig),
provider: provider,
}
} | go | func NewAuthServer(addr string, tlsConfig *tls.Config, provider auth.Provider) *AuthRemote {
return &AuthRemote{
Remote: NewServerTLS(addr, tlsConfig),
provider: provider,
}
} | [
"func",
"NewAuthServer",
"(",
"addr",
"string",
",",
"tlsConfig",
"*",
"tls",
".",
"Config",
",",
"provider",
"auth",
".",
"Provider",
")",
"*",
"AuthRemote",
"{",
"return",
"&",
"AuthRemote",
"{",
"Remote",
":",
"NewServerTLS",
"(",
"addr",
",",
"tlsConfig",
")",
",",
"provider",
":",
"provider",
",",
"}",
"\n",
"}"
] | // NewAuthServer sets up a new auth server target with an addr
// in the same format at NewServer and a default authentication provider to
// use for Sign requests. | [
"NewAuthServer",
"sets",
"up",
"a",
"new",
"auth",
"server",
"target",
"with",
"an",
"addr",
"in",
"the",
"same",
"format",
"at",
"NewServer",
"and",
"a",
"default",
"authentication",
"provider",
"to",
"use",
"for",
"Sign",
"requests",
"."
] | 768cd563887febaad559b511aaa5964823ccb4ab | https://github.com/cloudflare/cfssl/blob/768cd563887febaad559b511aaa5964823ccb4ab/api/client/client.go#L319-L324 | train |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.