Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openapi: mark object as actually base64 #2091

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/backfill-redis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func main() {
var insertErrs []error
for uuid, entry := range resp.Payload {
// uuid is the global UUID - tree ID and entry UUID
e, _, _, err := unmarshalEntryImpl(entry.Body.(string))
e, _, _, err := unmarshalEntryImpl(*entry.Body)
if err != nil {
parseErrs = append(parseErrs, fmt.Errorf("error unmarshalling entry for %s: %w", uuid, err))
continue
Expand Down
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ func parseEntry(uuid string, e models.LogEntryAnon) (interface{}, error) {
return tle.GenerateTransparencyLogEntry(e)
}

b, err := base64.StdEncoding.DecodeString(e.Body.(string))
b, err := base64.StdEncoding.DecodeString(*e.Body)
if err != nil {
return nil, err
}
Expand Down
6 changes: 2 additions & 4 deletions openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ definitions:
type: integer
minimum: 0
body:
type: object
additionalProperties: true
type: string
description: The base64-encoded proposed log entry
integratedTime:
type: integer
description: The time the entry was added to the log as a Unix timestamp in seconds
Expand All @@ -466,8 +466,6 @@ definitions:
properties:
data:
format: byte

format: byte
verification:
type: object
properties:
Expand Down
7 changes: 5 additions & 2 deletions pkg/api/entries.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package api
import (
"bytes"
"context"
"encoding/base64"
"encoding/hex"
"errors"
"fmt"
Expand Down Expand Up @@ -88,10 +89,11 @@ func logEntryFromLeaf(ctx context.Context, signer signature.Signer, _ trilliancl
}

virtualIndex := sharding.VirtualLogIndex(leaf.GetLeafIndex(), tid, ranges)
leafValue := base64.StdEncoding.EncodeToString(leaf.LeafValue)
logEntryAnon := models.LogEntryAnon{
LogID: swag.String(api.pubkeyHash),
LogIndex: &virtualIndex,
Body: leaf.LeafValue,
Body: &leafValue,
IntegratedTime: swag.Int64(leaf.IntegrateTimestamp.AsTime().Unix()),
}

Expand Down Expand Up @@ -239,10 +241,11 @@ func createLogEntry(params entries.CreateLogEntryParams) (models.LogEntry, middl

// The log index should be the virtual log index across all shards
virtualIndex := sharding.VirtualLogIndex(queuedLeaf.LeafIndex, api.logRanges.ActiveTreeID(), api.logRanges)
leafValue := base64.StdEncoding.EncodeToString(queuedLeaf.GetLeafValue())
logEntryAnon := models.LogEntryAnon{
LogID: swag.String(api.pubkeyHash),
LogIndex: swag.Int64(virtualIndex),
Body: queuedLeaf.GetLeafValue(),
Body: &leafValue,
IntegratedTime: swag.Int64(queuedLeaf.IntegrateTimestamp.AsTime().Unix()),
}

Expand Down
8 changes: 4 additions & 4 deletions pkg/generated/models/log_entry.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 5 additions & 8 deletions pkg/generated/restapi/embedded_spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 4 additions & 12 deletions pkg/tle/tle.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,12 @@ func GenerateTransparencyLogEntry(anon models.LogEntryAnon) (*rekor_pb.Transpare
inclusionProofHashes[i] = hashBytes
}

// Different call paths may supply string or []byte. If string, it is base64 encoded.
var body []byte
switch v := anon.Body.(type) {
case string:
b, err := base64.StdEncoding.DecodeString(v)
if err != nil {
return nil, fmt.Errorf("base64 decoding body: %w", err)
}
body = b
case []byte:
body = v
default:
return nil, fmt.Errorf("body is not string or []byte: (%T)%v", v, v)
b, err := base64.StdEncoding.DecodeString(*anon.Body)
if err != nil {
return nil, fmt.Errorf("base64 decoding body: %w", err)
}
body = b

pe, err := models.UnmarshalProposedEntry(bytes.NewReader(body), runtime.JSONConsumer())
if err != nil {
Expand Down
14 changes: 7 additions & 7 deletions pkg/tle/tle_test.go

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://rekor.sigstore.dev/types/rekord/rekord_v0_0_1_schema.json",
"$id": "http://rekor.sigstore.dev/types/rekord/hashedrekord_v0_0_1_schema.json",
"title": "Hashed Rekor v0.0.1 Schema",
"description": "Schema for Hashed Rekord object",
"type": "object",
Expand Down
2 changes: 1 addition & 1 deletion pkg/verify/verify.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func VerifyInclusion(ctx context.Context, e *models.LogEntryAnon) error {
}

// Verify the inclusion proof.
entryBytes, err := base64.StdEncoding.DecodeString(e.Body.(string))
entryBytes, err := base64.StdEncoding.DecodeString(*e.Body)
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/verify/verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func TestInclusion(t *testing.T) {
{
name: "valid inclusion",
e: models.LogEntryAnon{
Body: "eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoicmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiJlY2RjNTUzNmY3M2JkYWU4ODE2ZjBlYTQwNzI2ZWY1ZTliODEwZDkxNDQ5MzA3NTkwM2JiOTA2MjNkOTdiMWQ4In19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FWUNJUUQvUGRQUW1LV0MxKzBCTkVkNWdLdlFHcjF4eGwzaWVVZmZ2M2prMXp6Skt3SWhBTEJqM3hmQXlXeGx6NGpwb0lFSVYxVWZLOXZua1V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1oyeHlOVm80VERCS1RsTjFZWE41WldRNVQzUmhVblozUFQwS0xTMHRMUzFGVGtRZ1VGVkNURWxESUV0RldTMHRMUzB0Q2c9PSJ9fX19"),
IntegratedTime: &time,
LogID: &logID,
LogIndex: swag.Int64(1),
Expand All @@ -210,7 +210,7 @@ func TestInclusion(t *testing.T) {
{
name: "invalid inclusion - bad body hash",
e: models.LogEntryAnon{
Body: "ayJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoicmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiJlY2RjNTUzNmY3M2JkYWU4ODE2ZjBlYTQwNzI2ZWY1ZTliODEwZDkxNDQ5MzA3NTkwM2JiOTA2MjNkOTdiMWQ4In19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FWUNJUUQvUGRQUW1LV0MxKzBCTkVkNWdLdlFHcjF4eGwzaWVVZmZ2M2prMXp6Skt3SWhBTEJqM3hmQXlXeGx6NGpwb0lFSVYxVWZLOXZua1VVT1NvZVp4QlpQSEtQQyIsImZvcm1hdCI6Ing1MDkiLCJwdWJsaWNLZXkiOnsiY29udGVudCI6IkxTMHRMUzFDUlVkSlRpQlFWVUpNU1VNZ1MwVlpMUzB0TFMwS1RVWnJkMFYzV1VoTGIxcEplbW93UTBGUldVbExiMXBKZW1vd1JFRlJZMFJSWjBGRlRVOWpWR1pTUWxNNWFtbFlUVGd4UmxvNFoyMHZNU3R2YldWTmR3cHRiaTh6TkRjdk5UVTJaeTlzY21sVE56SjFUV2haT1V4alZDczFWVW8yWmtkQ1oyeHlOVm80VERCS1RsTjFZWE41WldRNVQzUmhVblozUFQwS0xTMHRMUzFGVGtRZ1VGVkNURWxESUV0RldTMHRMUzB0Q2c9PSJ9fX19",
Body: swag.String("ayJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoicmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiJlY2RjNTUzNmY3M2JkYWU4ODE2ZjBlYTQwNzI2ZWY1ZTliODEwZDkxNDQ5MzA3NTkwM2JiOTA2MjNkOTdiMWQ4In19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FWUNJUUQvUGRQUW1LV0MxKzBCTkVkNWdLdlFHcjF4eGwzaWVVZmZ2M2prMXp6Skt3SWhBTEJqM3hmQXlXeGx6NGpwb0lFSVYxVWZLOXZua1VVT1NvZVp4QlpQSEtQQyIsImZvcm1hdCI6Ing1MDkiLCJwdWJsaWNLZXkiOnsiY29udGVudCI6IkxTMHRMUzFDUlVkSlRpQlFWVUpNU1VNZ1MwVlpMUzB0TFMwS1RVWnJkMFYzV1VoTGIxcEplbW93UTBGUldVbExiMXBKZW1vd1JFRlJZMFJSWjBGRlRVOWpWR1pTUWxNNWFtbFlUVGd4UmxvNFoyMHZNU3R2YldWTmR3cHRiaTh6TkRjdk5UVTJaeTlzY21sVE56SjFUV2haT1V4alZDczFWVW8yWmtkQ1oyeHlOVm80VERCS1RsTjFZWE41WldRNVQzUmhVblozUFQwS0xTMHRMUzFGVGtRZ1VGVkNURWxESUV0RldTMHRMUzB0Q2c9PSJ9fX19"),
IntegratedTime: &time,
LogID: &logID,
LogIndex: swag.Int64(1),
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestCheckpoint(t *testing.T) {
{
name: "valid checkpoint",
e: models.LogEntryAnon{
Body: "eyJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoicmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiJlY2RjNTUzNmY3M2JkYWU4ODE2ZjBlYTQwNzI2ZWY1ZTliODEwZDkxNDQ5MzA3NTkwM2JiOTA2MjNkOTdiMWQ4In19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FWUNJUUQvUGRQUW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NWFtbFlUVGd4UmxvNFoyMHZNU3R2YldWTmR3cHRiaTh6TkRjdk5UVTJaeTlzY21sVE56SjFUV2haT1V4alZDczFWVW8yWmtkQ1oyeHlOVm80VERCS1RsTjFZWE41WldRNVQzUmhVblozUFQwS0xTMHRMUzFGVGtRZ1VGVkNURWxESUV0RldTMHRMUzB0Q2c9PSJ9fX19"),
IntegratedTime: &time,
LogID: &logID,
LogIndex: swag.Int64(1),
Expand All @@ -290,7 +290,7 @@ func TestCheckpoint(t *testing.T) {
{
name: "root hash mismatch",
e: models.LogEntryAnon{
Body: "ayJhcGlWZXJzaW9uIjoiMC4wLjEiLCJraW5kIjoicmVrb3JkIiwic3BlYyI6eyJkYXRhIjp7Imhhc2giOnsiYWxnb3JpdGhtIjoic2hhMjU2IiwidmFsdWUiOiJlY2RjNTUzNmY3M2JkYWU4ODE2ZjBlYTQwNzI2ZWY1ZTliODEwZDkxNDQ5MzA3NTkwM2JiOTA2MjNkOTdiMWQ4In19LCJzaWduYXR1cmUiOnsiY29udGVudCI6Ik1FWUNJUUQvUGRQUW1LV0MxKzBCTkVkNWdLdlFHcjF4eGwzaWVVZmZ2M2prMXp6Skt3SWhBTEJqM3hmQXlXeGx6NGpwb0lFSVYxVWZLOXZua1VVT1NvZVp4QlpQSEtQQyIsImZvcm1hdCI6Ing1MDkiLCJwdWJsaWNLZXkiOnsiY29udGVudCI6IkxTMHRMUzFDUlVkSlRpQlFWVUpNU1VNZ1MwVlpMUzB0TFMwS1RVWnJkMFYzV1VoTGIxcEplbW93UTBGUldVbExiMXBKZW1vd1JFRlJZMFJSWjBGRlRVOWpWR1pTUWxNNWFtbFlUVGd4UmxvNFoyMHZNU3R2YldWTmR3cHRiaTh6TkRjdk5UVTJaeTlzY21sVE56SjFUV2haT1V4alZDczFWVW8yWmtkQ1oyeHlOVm80VERCS1RsTjFZWE41WldRNVQzUmhVblozUFQwS0xTMHRMUzFGVGtRZ1VGVkNURWxESUV0RldTMHRMUzB0Q2c9PSJ9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