Skip to content

Commit 41dddc6

Browse files
committed
Now use SHA256 for OCI IAM instance principal fingerprint
1 parent bc9909a commit 41dddc6

File tree

5 files changed

+22
-9
lines changed

5 files changed

+22
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/).
1515
- nosqldb.Config.RateLimiterPercentage can control how much of a table's full limits this client handle can consume (default = 100%).
1616
- Result classes now have a GetRateLimitDelayed() method to return the amount of time an operation was delayed due to internal rate limiting.
1717

18+
### Changed
19+
- Now uses SHA256 for OCI IAM instance principal fingerprint
20+
1821
## 1.2.1 - 2020-08-14
1922

2023
### Added

nosqldb/auth/iam/federation_client.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func (client *authClient) Call(request *http.Request) (*http.Response, error) {
237237
func (c *x509FederationClient) KeyID() (string, error) {
238238
tenancy := c.tenancyID
239239
fingerprint := fingerprint(c.leafCertificateRetriever.Certificate())
240-
return fmt.Sprintf("%s/fed-x509/%s", tenancy, fingerprint), nil
240+
return fmt.Sprintf("%s/fed-x509-sha256/%s", tenancy, fingerprint), nil
241241
}
242242

243243
// For authClient to sign requests to X509 Federation Endpoint
@@ -403,6 +403,8 @@ type x509FederationRequest struct {
403403
Certificate string `json:"certificate,omitempty"`
404404
IntermediateCertificates []string `json:"intermediateCertificates,omitempty"`
405405
PublicKey string `json:"publicKey,omitempty"`
406+
FingerprintAlgorithm string `json:"fingerprintAlgorithm,omitempty"`
407+
Purpose string `json:"purpose,omitempty"`
406408
}
407409

408410
// type X509FederationRequest struct {
@@ -438,6 +440,8 @@ func (c *x509FederationClient) makeX509FederationRequest() *x509FederationReques
438440
Certificate: certificate,
439441
IntermediateCertificates: intermediateCertificates,
440442
PublicKey: publicKey,
443+
FingerprintAlgorithm: `SHA256`,
444+
Purpose: `DEFAULT`,
441445
// },
442446
}
443447
}

nosqldb/auth/iam/federation_client_test.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ import (
2121
func TestX509FederationClient_VeryFirstSecurityToken(t *testing.T) {
2222
authServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
2323
// Verify request
24-
expectedKeyID := fmt.Sprintf("%s/fed-x509/%s", tenancyID, leafCertFingerprint)
24+
expectedKeyID := fmt.Sprintf("%s/fed-x509-sha256/%s", tenancyID, leafCertFingerprint)
2525
assert.True(t, strings.HasPrefix(r.Header.Get("Authorization"), fmt.Sprintf(`Signature version="1",headers="date (request-target) content-length content-type x-content-sha256",keyId="%s",algorithm="rsa-sha256",signature=`, expectedKeyID)))
26-
expectedBody := fmt.Sprintf(`{"certificate":"%s","intermediateCertificates":["%s"],"publicKey":"%s"}`,
26+
expectedBody := fmt.Sprintf(`{"certificate":"%s","intermediateCertificates":["%s"],"publicKey":"%s","fingerprintAlgorithm":"SHA256","purpose":"DEFAULT"}`,
2727
leafCertBodyNoNewLine, intermediateCertBodyNoNewLine, sessionPublicKeyBodyNoNewLine)
2828

2929
var buf bytes.Buffer
@@ -72,10 +72,10 @@ func TestX509FederationClient_VeryFirstSecurityToken(t *testing.T) {
7272
func TestX509FederationClient_RenewSecurityToken(t *testing.T) {
7373
authServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
7474
// Verify request
75-
expectedKeyID := fmt.Sprintf("%s/fed-x509/%s", tenancyID, leafCertFingerprint)
75+
expectedKeyID := fmt.Sprintf("%s/fed-x509-sha256/%s", tenancyID, leafCertFingerprint)
7676
assert.True(t, strings.HasPrefix(r.Header.Get("Authorization"), fmt.Sprintf(`Signature version="1",headers="date (request-target) content-length content-type x-content-sha256",keyId="%s",algorithm="rsa-sha256",signature=`, expectedKeyID)))
7777

78-
expectedBody := fmt.Sprintf(`{"certificate":"%s","intermediateCertificates":["%s"],"publicKey":"%s"}`,
78+
expectedBody := fmt.Sprintf(`{"certificate":"%s","intermediateCertificates":["%s"],"publicKey":"%s","fingerprintAlgorithm":"SHA256","purpose":"DEFAULT"}`,
7979
leafCertBodyNoNewLine, intermediateCertBodyNoNewLine, sessionPublicKeyBodyNoNewLine)
8080
var buf bytes.Buffer
8181
buf.ReadFrom(r.Body)
@@ -430,7 +430,12 @@ ysvMnQwaC0432ceRJ3r6vPAI2EPRd9KOE7Va1IFNJNmOuIkmRx8t`
430430
// certPem = pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: newCertBytes})
431431
// return
432432
//}
433-
leafCertFingerprint = `52:3c:9d:93:8b:b8:07:21:ce:36:30:98:ba:fc:e2:4a:bc:3a:2e:0b`
433+
434+
// old SHA-1 fingerprint
435+
//leafCertFingerprint = `52:3c:9d:93:8b:b8:07:21:ce:36:30:98:ba:fc:e2:4a:bc:3a:2e:0b`
436+
437+
// new SHA-256 fingerprint
438+
leafCertFingerprint = `0c:1e:d8:13:80:d4:30:cc:2c:62:13:57:2a:fe:d5:4e:75:be:54:32:59:12:8f:2f:96:78:f8:b1:f3:62:78:bc`
434439
intermediateCertBody = `MIIC4TCCAcmgAwIBAgIRAK7jQKVEO6ssUBICuPw4OwQwDQYJKoZIhvcNAQELBQAw
435440
KjEoMCYGA1UEAxMfUEtJU1ZDIElkZW50aXR5IEludGVybWVkaWF0ZSByMjAeFw0x
436441
NzExMzAwMDE0MDhaFw0xODExMzAwMDE0MDhaMCoxKDAmBgNVBAMTH1BLSVNWQyBJ

nosqldb/auth/iam/helpers.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package iam
66
import (
77
"bytes"
88
"crypto/rsa"
9-
"crypto/sha1"
9+
"crypto/sha256"
1010
"crypto/x509"
1111
"encoding/pem"
1212
"fmt"
@@ -104,11 +104,11 @@ func extractTenancyIDFromCertificate(cert *x509.Certificate) string {
104104
}
105105

106106
func fingerprint(certificate *x509.Certificate) string {
107-
fingerprint := sha1.Sum(certificate.Raw)
107+
fingerprint := sha256.Sum256(certificate.Raw)
108108
return colonSeparatedString(fingerprint)
109109
}
110110

111-
func colonSeparatedString(fingerprint [sha1.Size]byte) string {
111+
func colonSeparatedString(fingerprint [sha256.Size]byte) string {
112112
spaceSeparated := fmt.Sprintf("% x", fingerprint)
113113
return strings.Replace(spaceSeparated, " ", ":", -1)
114114
}

nosqldb/types/types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ func (ttl TimeToLive) ToDuration() time.Duration {
206206

207207
// ISO8601Layout represents the ISO 8601 format of Go's reference time.
208208
const ISO8601Layout = "2006-01-02T15:04:05.999999999"
209+
209210
// ISO8601ZLayout includes literal "Z"
210211
const ISO8601ZLayout = "2006-01-02T15:04:05.999999999Z"
211212

0 commit comments

Comments
 (0)