Skip to content

Commit 6a82a2e

Browse files
Change serial number from bytes to string (#944)
* change serial from bytes to string and removed max length validation from the serial number fields
1 parent da6adb1 commit 6a82a2e

File tree

6 files changed

+132
-140
lines changed

6 files changed

+132
-140
lines changed

api/grpc/mpi/v1/files.pb.go

Lines changed: 123 additions & 123 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/grpc/mpi/v1/files.proto

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ message UpdateFileResponse {
151151
// Define the certificate message based on https://pkg.go.dev/crypto/x509#Certificate
152152
// and https://github.com/googleapis/googleapis/blob/005df4681b89bd204a90b76168a6dc9d9e7bf4fe/google/cloud/iot/v1/resources.proto#L341
153153
message CertificateMeta {
154-
// Serial number of the certificate, usually a unique identifier, RFC5280 states the upper limit for serial number is 20 octets
155-
bytes serial_number = 1 [(buf.validate.field).bytes.min_len = 0, (buf.validate.field).bytes.max_len = 21];
154+
// Serial number of the certificate, usually a unique identifier, the max length is the length of an interger
155+
string serial_number = 1 [(buf.validate.field).string.min_len = 0];
156156

157157
// Issuer details (who issued the certificate)
158158
X509Name issuer = 2;
@@ -270,7 +270,7 @@ message X509Name {
270270
repeated string postal_code = 7 [(buf.validate.field).repeated.items.string.min_len = 1];
271271

272272
// Serial Number (SN): Unique identifier or serial number.
273-
string serial_number = 8 [(buf.validate.field).string.min_len = 0, (buf.validate.field).string.max_len = 21];
273+
string serial_number = 8 [(buf.validate.field).string.min_len = 0];
274274

275275
// Common Name (CN): Typically the person’s or entity's full name.
276276
string common_name = 9 [(buf.validate.field).string.min_len = 1];

docs/proto/protos.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ and https://github.com/googleapis/googleapis/blob/005df4681b89bd204a90b76168a6dc
256256

257257
| Field | Type | Label | Description |
258258
| ----- | ---- | ----- | ----------- |
259-
| serial_number | [bytes](#bytes) | | Serial number of the certificate, usually a unique identifier, RFC5280 states the upper limit for serial number is 20 octets |
259+
| serial_number | [string](#string) | | Serial number of the certificate, usually a unique identifier, the max length is the length of an interger |
260260
| issuer | [X509Name](#mpi-v1-X509Name) | | Issuer details (who issued the certificate) |
261261
| subject | [X509Name](#mpi-v1-X509Name) | | Subject details (to whom the certificate is issued) |
262262
| sans | [SubjectAlternativeNames](#mpi-v1-SubjectAlternativeNames) | | Subject Alternative Names (SAN) including DNS names and IP addresses |

internal/file/file_manager_service_test.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -648,13 +648,13 @@ func TestParseX509Certificates(t *testing.T) {
648648
certName string
649649
certContent string
650650
name string
651-
expectedSerial []byte
651+
expectedSerial string
652652
}{
653653
{
654654
name: "Test 1: generated cert",
655655
certName: "public_cert",
656656
certContent: "",
657-
expectedSerial: []byte{0x1, 0xe0, 0xf3},
657+
expectedSerial: "123123",
658658
},
659659
{
660660
name: "Test 2: open ssl cert",
@@ -680,15 +680,7 @@ X/vYrzgKRoKSUWUt1ejKTntrVuaJK4NMxANOTTjIXgxyoV3YcgEmL9KzribCqILi
680680
p79Nno9d+kovtX5VKsJ5FCcPw9mEATgZDOQ4nLTk/HHG6bwtpubp6Zb7H1AjzBkz
681681
rQHX6DP4w6IwZY8JB8LS
682682
-----END CERTIFICATE-----`,
683-
expectedSerial: []byte{
684-
0x47, 0xe6, 0x6,
685-
0x81, 0x11, 0xe1,
686-
0x63, 0xa, 0x2d,
687-
0x17, 0x20, 0x4e,
688-
0xbd, 0x27, 0x35,
689-
0x28, 0x3f, 0x5d,
690-
0xe3, 0x99,
691-
},
683+
expectedSerial: "410468082718062724391949173062901619571168240537",
692684
},
693685
}
694686

pkg/files/file_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func FileMetaWithCertificate(filePath string) (*mpi.FileMeta, error) {
6464
// Populate certificate-specific metadata
6565
fileMeta.FileType = &mpi.FileMeta_CertificateMeta{
6666
CertificateMeta: &mpi.CertificateMeta{
67-
SerialNumber: loadedCert.SerialNumber.Bytes(),
67+
SerialNumber: loadedCert.SerialNumber.String(),
6868
Issuer: &mpi.X509Name{
6969
Country: loadedCert.Issuer.Country,
7070
Organization: loadedCert.Issuer.Organization,

test/protos/files.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func CertMeta(fileName, fileHash string) *mpi.FileMeta {
3131
Permissions: "0600",
3232
FileType: &mpi.FileMeta_CertificateMeta{
3333
CertificateMeta: &mpi.CertificateMeta{
34-
SerialNumber: []byte("12345-67890"),
34+
SerialNumber: "12345-67890",
3535
Issuer: &mpi.X509Name{
3636
Country: []string{"IE"},
3737
Organization: []string{"F5"},

0 commit comments

Comments
 (0)