Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
3e5d78e2
Unverified
Commit
3e5d78e2
authored
Feb 04, 2017
by
Christoph Blecker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PKCS#8 support to ParsePrivateKeyPEM
parent
89d1b09f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
6 deletions
+22
-6
pem.go
staging/src/k8s.io/client-go/util/cert/pem.go
+22
-6
No files found.
staging/src/k8s.io/client-go/util/cert/pem.go
View file @
3e5d78e2
...
...
@@ -56,23 +56,39 @@ func EncodeCertPEM(cert *x509.Certificate) []byte {
}
// ParsePrivateKeyPEM returns a private key parsed from a PEM block in the supplied data.
// Recognizes PEM blocks for "EC PRIVATE KEY"
and "RSA
PRIVATE KEY"
// Recognizes PEM blocks for "EC PRIVATE KEY"
, "RSA PRIVATE KEY", or "
PRIVATE KEY"
func
ParsePrivateKeyPEM
(
keyData
[]
byte
)
(
interface
{},
error
)
{
var
privateKeyPemBlock
*
pem
.
Block
for
{
var
privateKeyPemBlock
*
pem
.
Block
privateKeyPemBlock
,
keyData
=
pem
.
Decode
(
keyData
)
if
privateKeyPemBlock
==
nil
{
// we read all the PEM blocks and didn't recognize one
return
nil
,
fmt
.
Errorf
(
"no private key PEM block found"
)
break
}
switch
privateKeyPemBlock
.
Type
{
case
"EC PRIVATE KEY"
:
return
x509
.
ParseECPrivateKey
(
privateKeyPemBlock
.
Bytes
)
// ECDSA Private Key in ASN.1 format
if
key
,
err
:=
x509
.
ParseECPrivateKey
(
privateKeyPemBlock
.
Bytes
);
err
==
nil
{
return
key
,
nil
}
case
"RSA PRIVATE KEY"
:
return
x509
.
ParsePKCS1PrivateKey
(
privateKeyPemBlock
.
Bytes
)
// RSA Private Key in PKCS#1 format
if
key
,
err
:=
x509
.
ParsePKCS1PrivateKey
(
privateKeyPemBlock
.
Bytes
);
err
==
nil
{
return
key
,
nil
}
case
"PRIVATE KEY"
:
// RSA or ECDSA Private Key in unencrypted PKCS#8 format
if
key
,
err
:=
x509
.
ParsePKCS8PrivateKey
(
privateKeyPemBlock
.
Bytes
);
err
==
nil
{
return
key
,
nil
}
}
// tolerate non-key PEM blocks for compatibility with things like "EC PARAMETERS" blocks
// originally, only the first PEM block was parsed and expected to be a key block
}
// we read all the PEM blocks and didn't recognize one
return
nil
,
fmt
.
Errorf
(
"data does not contain a valid RSA or ECDSA private key"
)
}
// ParseCertsPEM returns the x509.Certificates contained in the given PEM-encoded byte array
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment