generated from interTwin-eu/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from interTwin-eu/main
rebase v0.0.2 for patch
- Loading branch information
Showing
3,503 changed files
with
626,464 additions
and
142,581 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ token | |
secret.yaml | ||
configmap.yaml | ||
kubeconfig.yaml | ||
kubeconfigVEGA.yaml | ||
serviceaccount.yaml | ||
.knoc | ||
.tmp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package main | ||
|
||
import ( | ||
"crypto/ed25519" | ||
cryptorand "crypto/rand" | ||
"crypto/tls" | ||
"crypto/x509" | ||
"crypto/x509/pkix" | ||
"encoding/pem" | ||
"fmt" | ||
"math/big" | ||
"math/rand" | ||
"net" | ||
"time" | ||
) | ||
|
||
type crtretriever func(*tls.ClientHelloInfo) (*tls.Certificate, error) | ||
|
||
// newSelfSignedCertificateRetriever creates a new retriever for self-signed certificates. | ||
func newSelfSignedCertificateRetriever(nodeName string, nodeIP net.IP) crtretriever { | ||
creator := func() (*tls.Certificate, time.Time, error) { | ||
expiration := time.Now().AddDate(1, 0, 0) // 1 year | ||
|
||
// Generate a new private key. | ||
publicKey, privateKey, err := ed25519.GenerateKey(cryptorand.Reader) | ||
if err != nil { | ||
return nil, expiration, fmt.Errorf("failed to generate a key pair: %w", err) | ||
} | ||
|
||
keyBytes, err := x509.MarshalPKCS8PrivateKey(privateKey) | ||
if err != nil { | ||
return nil, expiration, fmt.Errorf("failed to marshal the private key: %w", err) | ||
} | ||
|
||
// Generate the corresponding certificate. | ||
cert := &x509.Certificate{ | ||
Subject: pkix.Name{ | ||
CommonName: fmt.Sprintf("system:node:%s", nodeName), | ||
Organization: []string{"intertwin.eu"}, | ||
}, | ||
IPAddresses: []net.IP{nodeIP}, | ||
SerialNumber: big.NewInt(rand.Int63()), //nolint:gosec // A weak random generator is sufficient. | ||
NotBefore: time.Now(), | ||
NotAfter: expiration, | ||
KeyUsage: x509.KeyUsageDigitalSignature, | ||
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth, x509.ExtKeyUsageServerAuth}, | ||
} | ||
|
||
certBytes, err := x509.CreateCertificate(cryptorand.Reader, cert, cert, publicKey, privateKey) | ||
if err != nil { | ||
return nil, expiration, fmt.Errorf("failed to create the self-signed certificate: %w", err) | ||
} | ||
|
||
// Encode the resulting certificate and private key as a single object. | ||
output, err := tls.X509KeyPair( | ||
pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certBytes}), | ||
pem.EncodeToMemory(&pem.Block{Type: "PRIVATE KEY", Bytes: keyBytes})) | ||
if err != nil { | ||
return nil, expiration, fmt.Errorf("failed to create the X509 key pair: %w", err) | ||
} | ||
|
||
return &output, expiration, nil | ||
} | ||
|
||
// Cache the last generated cert, until it is not expired. | ||
var cert *tls.Certificate | ||
var expiration time.Time | ||
return func(*tls.ClientHelloInfo) (*tls.Certificate, error) { | ||
if cert == nil || expiration.Before(time.Now().AddDate(0, 0, 1)) { | ||
var err error | ||
cert, expiration, err = creator() | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return cert, nil | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.