You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
propose approach and syntax for "sugary" content digests #194
While the digests provide a lot of benefits, they are long and unwieldy for users. To mitigate this, we should propose a syntax for shortening identifiers, much in the way git does. It should meet at least the following requirements:
Resolves content uniquely with a low probability of collision
Shortened digests should not leak into persistent systems
My only concern from a security end is that using a shortened identifier will then require a trust check. Which means the shortened identifier needs to be registered with the trust system. The vulnerability being that at some point the shortened identifier needs to be resolved to a full hash. If it is simply trusting the registry to provide the full hash, then the operation is no longer trusted. Yes git may allow using shortened IDs, but that is under the assumption the client has the full view of the repository and therefore able to detect ID collisions for itself.
A possible solution may be for the client to download a taglist, which will require a trust check. Once the client has the tag list, it would then be able to expand the identifier for itself. If that is the best solution, then this is a client side operation, possibly we should just provide a trusted list of hashes + utility for resolving.
@dmcgowan Should all sets of digest be concrete, in-memory to enforce some notion of transformation?
Something like this would be a mutable implementation:
type Digests digestEntries
func (ds Digests) Lookup(short string) Digest {
// use http://golang.org/pkg/sort/#Search to find prefix
}
func (ds Digests) Add(d Digest) error {
// insort the digest using http://golang.org/pkg/sort/#Search
// slightly expensive memory wise, maybe.
}
type digestEntry struct {
alg string
digest string
}
type digestEntries []digestEntry
// sort methods
func (d digestEntries) Len() int {}
func (d digestEntries) Less(i, j int) bool
func (d digestEntries) Swap(i, j int)
An immutable implementation would be something like this, using suffix array:
// Note that we have record markers on either end to make finding complete
// record easier.
data := []byte("\nsha256:asdfasdfasdfasdfasdf\nsha256:qwerqwerqwerqwer\nsha256:01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b\n")
index := suffixarray.New(data)
short := os.Args[1]
// If an algorithem is not specified, affix the query to the colon
if !strings.Contains(short, ":") {
short = ":" + short
}
results := index.Lookup([]byte(short), 2)
if len(results) > 1 {
fmt.Println("short hash not unique")
os.Exit(1)
}
for _, result := range results {
start := bytes.LastIndex(data[:result], []byte("\n"))
end := bytes.Index(data[result:], []byte("\n")) + result
record := data[start+1 : end]
fmt.Println(string(record))
}
I like the first section, the only function I would add is to get a map of Digest to short code
func (ds Digests) ShortMap(length int) map[Digest]string {
// Provides unique short codes for each digest with minimum of length
// If two digests have the same prefix of minimum length, the minimum
// unique prefix will be returned, which may be the entire digest string
}
Activity
dmcgowan commentedon Feb 20, 2015
My only concern from a security end is that using a shortened identifier will then require a trust check. Which means the shortened identifier needs to be registered with the trust system. The vulnerability being that at some point the shortened identifier needs to be resolved to a full hash. If it is simply trusting the registry to provide the full hash, then the operation is no longer trusted. Yes git may allow using shortened IDs, but that is under the assumption the client has the full view of the repository and therefore able to detect ID collisions for itself.
dmcgowan commentedon Feb 20, 2015
A possible solution may be for the client to download a taglist, which will require a trust check. Once the client has the tag list, it would then be able to expand the identifier for itself. If that is the best solution, then this is a client side operation, possibly we should just provide a trusted list of hashes + utility for resolving.
stevvooe commentedon Mar 11, 2015
@dmcgowan Should all sets of digest be concrete, in-memory to enforce some notion of transformation?
Something like this would be a mutable implementation:
An immutable implementation would be something like this, using suffix array:
dmcgowan commentedon Mar 11, 2015
I like the first section, the only function I would add is to get a map of Digest to short code