Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Hepto
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ACIDES
Hepto
Commits
4de32274
Commit
4de32274
authored
2 years ago
by
kaiyou
Browse files
Options
Downloads
Patches
Plain Diff
Add ip SAN and temporary storage
parent
fceeb2a9
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/pki/cert.go
+14
-0
14 additions, 0 deletions
pkg/pki/cert.go
pkg/pki/templates.go
+13
-5
13 additions, 5 deletions
pkg/pki/templates.go
with
27 additions
and
5 deletions
pkg/pki/cert.go
+
14
−
0
View file @
4de32274
...
...
@@ -7,6 +7,7 @@ import (
"crypto/rand"
"crypto/x509"
"errors"
"io/ioutil"
)
type
Cert
struct
{
...
...
@@ -90,13 +91,26 @@ func (c *Certificate) Save() error {
return
nil
}
// Ensure that the certificate has IO available
// Certificates without explicit IO will get a
// temporary directory
func
(
c
*
Certificate
)
ensureIO
()
{
if
c
.
IO
==
nil
{
dir
,
_
:=
ioutil
.
TempDir
(
"/tmp"
,
"cert-"
)
c
.
IO
=
FileIO
{
dir
}
c
.
Save
()
}
}
// Get the key file path
func
(
c
*
Certificate
)
KeyPath
()
string
{
c
.
ensureIO
()
return
c
.
IO
.
Path
(
KeyType
)
}
// Get the certificate file path
func
(
c
*
Certificate
)
CertPath
()
string
{
c
.
ensureIO
()
return
c
.
IO
.
Path
(
CertType
)
}
...
...
This diff is collapsed.
Click to expand it.
pkg/pki/templates.go
+
13
−
5
View file @
4de32274
...
...
@@ -5,6 +5,7 @@ import (
"crypto/x509"
"crypto/x509/pkix"
"math/big"
"net"
"time"
)
...
...
@@ -30,18 +31,23 @@ func newTemplate() *x509.Certificate {
func
NewCATemplate
()
*
x509
.
Certificate
{
template
:=
newTemplate
()
template
.
Subject
=
pkix
.
Name
{}
template
.
KeyUsage
=
x509
.
KeyUsageDigitalSignature
|
x509
.
KeyUsageCertSign
template
.
ExtKeyUsage
=
[]
x509
.
ExtKeyUsage
{
x509
.
ExtKeyUsageServerAuth
}
template
.
KeyUsage
=
x509
.
KeyUsageCertSign
|
x509
.
KeyUsageCRLSign
template
.
IsCA
=
true
return
template
}
func
NewServerTemplate
(
names
[]
string
)
*
x509
.
Certificate
{
func
NewServerTemplate
(
names
[]
string
,
ips
[]
net
.
IP
)
*
x509
.
Certificate
{
template
:=
newTemplate
()
template
.
Subject
=
pkix
.
Name
{
CommonName
:
names
[
0
],
template
.
Subject
=
pkix
.
Name
{}
if
len
(
names
)
>
0
{
template
.
Subject
.
CommonName
=
names
[
0
]
}
else
if
len
(
ips
)
>
0
{
template
.
Subject
.
CommonName
=
ips
[
0
]
.
String
()
}
template
.
KeyUsage
=
x509
.
KeyUsageDigitalSignature
|
x509
.
KeyUsageKeyEncipherment
template
.
ExtKeyUsage
=
[]
x509
.
ExtKeyUsage
{
x509
.
ExtKeyUsageServerAuth
}
template
.
DNSNames
=
names
template
.
IPAddresses
=
ips
return
template
}
...
...
@@ -51,5 +57,7 @@ func NewClientTemplate(cn string, org string) *x509.Certificate {
CommonName
:
cn
,
Organization
:
[]
string
{
org
},
}
template
.
KeyUsage
=
x509
.
KeyUsageDigitalSignature
|
x509
.
KeyUsageKeyEncipherment
template
.
ExtKeyUsage
=
[]
x509
.
ExtKeyUsage
{
x509
.
ExtKeyUsageClientAuth
}
return
template
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment