mirror of
				https://github.com/moby/moby.git
				synced 2022-11-09 12:21:53 -05:00 
			
		
		
		
	Replace GenerateRandomID with GenerateNonCryptoID
This allow us to avoid entropy usage in non-crypto critical places. Signed-off-by: Alexander Morozov <lk4d4@docker.com>
This commit is contained in:
		
							parent
							
								
									4553b6af4b
								
							
						
					
					
						commit
						6bca8ec3c9
					
				
					 11 changed files with 32 additions and 32 deletions
				
			
		| 
						 | 
				
			
			@ -11,7 +11,7 @@ import (
 | 
			
		|||
)
 | 
			
		||||
 | 
			
		||||
func TestContainerContextID(t *testing.T) {
 | 
			
		||||
	containerId := stringid.GenerateRandomID()
 | 
			
		||||
	containerId := stringid.GenerateNonCryptoID()
 | 
			
		||||
	unix := time.Now().Unix()
 | 
			
		||||
 | 
			
		||||
	var ctx containerContext
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -24,7 +24,7 @@ func createContainerPlatformSpecificSettings(container *Container, config *runco
 | 
			
		|||
		case 2:
 | 
			
		||||
			name, destination = parts[0], filepath.Clean(parts[1])
 | 
			
		||||
		default:
 | 
			
		||||
			name = stringid.GenerateRandomID()
 | 
			
		||||
			name = stringid.GenerateNonCryptoID()
 | 
			
		||||
			destination = filepath.Clean(parts[0])
 | 
			
		||||
		}
 | 
			
		||||
		// Skip volumes for which we already have something mounted on that
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -350,7 +350,7 @@ func (daemon *Daemon) mergeAndVerifyConfig(config *runconfig.Config, img *image.
 | 
			
		|||
func (daemon *Daemon) generateIdAndName(name string) (string, string, error) {
 | 
			
		||||
	var (
 | 
			
		||||
		err error
 | 
			
		||||
		id  = stringid.GenerateRandomID()
 | 
			
		||||
		id  = stringid.GenerateNonCryptoID()
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	if name == "" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -135,7 +135,7 @@ func TestLoadWithVolume(t *testing.T) {
 | 
			
		|||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	hostVolumeId := stringid.GenerateRandomID()
 | 
			
		||||
	hostVolumeId := stringid.GenerateNonCryptoID()
 | 
			
		||||
	vfsPath := filepath.Join(tmp, "vfs", "dir", hostVolumeId)
 | 
			
		||||
	volumePath := filepath.Join(tmp, "volumes", hostVolumeId)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -419,7 +419,7 @@ func TestRemoveLocalVolumesFollowingSymlinks(t *testing.T) {
 | 
			
		|||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	hostVolumeId := stringid.GenerateRandomID()
 | 
			
		||||
	hostVolumeId := stringid.GenerateNonCryptoID()
 | 
			
		||||
	vfsPath := filepath.Join(tmp, "vfs", "dir", hostVolumeId)
 | 
			
		||||
	volumePath := filepath.Join(tmp, "volumes", hostVolumeId)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -155,7 +155,7 @@ func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, erro
 | 
			
		|||
	}
 | 
			
		||||
 | 
			
		||||
	execConfig := &execConfig{
 | 
			
		||||
		ID:            stringid.GenerateRandomID(),
 | 
			
		||||
		ID:            stringid.GenerateNonCryptoID(),
 | 
			
		||||
		OpenStdin:     config.AttachStdin,
 | 
			
		||||
		OpenStdout:    config.AttachStdout,
 | 
			
		||||
		OpenStderr:    config.AttachStderr,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -19,7 +19,7 @@ func (d *driver) Exec(c *execdriver.Command, processConfig *execdriver.ProcessCo
 | 
			
		|||
		inListen, outListen, errListen     *npipe.PipeListener
 | 
			
		||||
		term                               execdriver.Terminal
 | 
			
		||||
		err                                error
 | 
			
		||||
		randomID                           string = stringid.GenerateRandomID()
 | 
			
		||||
		randomID                           string = stringid.GenerateNonCryptoID()
 | 
			
		||||
		serverPipeFormat, clientPipeFormat string
 | 
			
		||||
		pid                                uint32
 | 
			
		||||
		exitCode                           int32
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -314,7 +314,7 @@ func (graph *Graph) TempLayerArchive(id string, sf *streamformatter.StreamFormat
 | 
			
		|||
 | 
			
		||||
// mktemp creates a temporary sub-directory inside the graph's filesystem.
 | 
			
		||||
func (graph *Graph) mktemp(id string) (string, error) {
 | 
			
		||||
	dir := filepath.Join(graph.root, "_tmp", stringid.GenerateRandomID())
 | 
			
		||||
	dir := filepath.Join(graph.root, "_tmp", stringid.GenerateNonCryptoID())
 | 
			
		||||
	if err := system.MkdirAll(dir, 0700); err != nil {
 | 
			
		||||
		return "", err
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -68,7 +68,7 @@ func TestInterruptedRegister(t *testing.T) {
 | 
			
		|||
	defer nukeGraph(graph)
 | 
			
		||||
	badArchive, w := io.Pipe() // Use a pipe reader as a fake archive which never yields data
 | 
			
		||||
	image := &image.Image{
 | 
			
		||||
		ID:      stringid.GenerateRandomID(),
 | 
			
		||||
		ID:      stringid.GenerateNonCryptoID(),
 | 
			
		||||
		Comment: "testing",
 | 
			
		||||
		Created: time.Now(),
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -126,7 +126,7 @@ func TestRegister(t *testing.T) {
 | 
			
		|||
		t.Fatal(err)
 | 
			
		||||
	}
 | 
			
		||||
	image := &image.Image{
 | 
			
		||||
		ID:      stringid.GenerateRandomID(),
 | 
			
		||||
		ID:      stringid.GenerateNonCryptoID(),
 | 
			
		||||
		Comment: "testing",
 | 
			
		||||
		Created: time.Now(),
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -229,19 +229,19 @@ func TestByParent(t *testing.T) {
 | 
			
		|||
	graph, _ := tempGraph(t)
 | 
			
		||||
	defer nukeGraph(graph)
 | 
			
		||||
	parentImage := &image.Image{
 | 
			
		||||
		ID:      stringid.GenerateRandomID(),
 | 
			
		||||
		ID:      stringid.GenerateNonCryptoID(),
 | 
			
		||||
		Comment: "parent",
 | 
			
		||||
		Created: time.Now(),
 | 
			
		||||
		Parent:  "",
 | 
			
		||||
	}
 | 
			
		||||
	childImage1 := &image.Image{
 | 
			
		||||
		ID:      stringid.GenerateRandomID(),
 | 
			
		||||
		ID:      stringid.GenerateNonCryptoID(),
 | 
			
		||||
		Comment: "child1",
 | 
			
		||||
		Created: time.Now(),
 | 
			
		||||
		Parent:  parentImage.ID,
 | 
			
		||||
	}
 | 
			
		||||
	childImage2 := &image.Image{
 | 
			
		||||
		ID:      stringid.GenerateRandomID(),
 | 
			
		||||
		ID:      stringid.GenerateNonCryptoID(),
 | 
			
		||||
		Comment: "child2",
 | 
			
		||||
		Created: time.Now(),
 | 
			
		||||
		Parent:  parentImage.ID,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,7 @@ func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) {
 | 
			
		|||
	dockerCmd(c, "wait", cleanedContainerID)
 | 
			
		||||
 | 
			
		||||
	name, err := inspectField(cleanedContainerID, "Name")
 | 
			
		||||
	newName := "new_name" + stringid.GenerateRandomID()
 | 
			
		||||
	newName := "new_name" + stringid.GenerateNonCryptoID()
 | 
			
		||||
	dockerCmd(c, "rename", "first_name", newName)
 | 
			
		||||
 | 
			
		||||
	name, err = inspectField(cleanedContainerID, "Name")
 | 
			
		||||
| 
						 | 
				
			
			@ -30,7 +30,7 @@ func (s *DockerSuite) TestRenameStoppedContainer(c *check.C) {
 | 
			
		|||
func (s *DockerSuite) TestRenameRunningContainer(c *check.C) {
 | 
			
		||||
	out, _ := dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh")
 | 
			
		||||
 | 
			
		||||
	newName := "new_name" + stringid.GenerateRandomID()
 | 
			
		||||
	newName := "new_name" + stringid.GenerateNonCryptoID()
 | 
			
		||||
	cleanedContainerID := strings.TrimSpace(out)
 | 
			
		||||
	dockerCmd(c, "rename", "first_name", newName)
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -46,7 +46,7 @@ func (s *DockerSuite) TestRenameRunningContainer(c *check.C) {
 | 
			
		|||
func (s *DockerSuite) TestRenameCheckNames(c *check.C) {
 | 
			
		||||
	dockerCmd(c, "run", "--name", "first_name", "-d", "busybox", "sh")
 | 
			
		||||
 | 
			
		||||
	newName := "new_name" + stringid.GenerateRandomID()
 | 
			
		||||
	newName := "new_name" + stringid.GenerateNonCryptoID()
 | 
			
		||||
	dockerCmd(c, "rename", "first_name", newName)
 | 
			
		||||
 | 
			
		||||
	name, err := inspectField(newName, "Name")
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -134,7 +134,7 @@ func assertIndexGet(t *testing.T, index *TruncIndex, input, expectedResult strin
 | 
			
		|||
func BenchmarkTruncIndexAdd100(b *testing.B) {
 | 
			
		||||
	var testSet []string
 | 
			
		||||
	for i := 0; i < 100; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
	for i := 0; i < b.N; i++ {
 | 
			
		||||
| 
						 | 
				
			
			@ -150,7 +150,7 @@ func BenchmarkTruncIndexAdd100(b *testing.B) {
 | 
			
		|||
func BenchmarkTruncIndexAdd250(b *testing.B) {
 | 
			
		||||
	var testSet []string
 | 
			
		||||
	for i := 0; i < 250; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
	for i := 0; i < b.N; i++ {
 | 
			
		||||
| 
						 | 
				
			
			@ -166,7 +166,7 @@ func BenchmarkTruncIndexAdd250(b *testing.B) {
 | 
			
		|||
func BenchmarkTruncIndexAdd500(b *testing.B) {
 | 
			
		||||
	var testSet []string
 | 
			
		||||
	for i := 0; i < 500; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
	for i := 0; i < b.N; i++ {
 | 
			
		||||
| 
						 | 
				
			
			@ -183,7 +183,7 @@ func BenchmarkTruncIndexGet100(b *testing.B) {
 | 
			
		|||
	var testSet []string
 | 
			
		||||
	var testKeys []string
 | 
			
		||||
	for i := 0; i < 100; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	index := NewTruncIndex([]string{})
 | 
			
		||||
	for _, id := range testSet {
 | 
			
		||||
| 
						 | 
				
			
			@ -207,7 +207,7 @@ func BenchmarkTruncIndexGet250(b *testing.B) {
 | 
			
		|||
	var testSet []string
 | 
			
		||||
	var testKeys []string
 | 
			
		||||
	for i := 0; i < 250; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	index := NewTruncIndex([]string{})
 | 
			
		||||
	for _, id := range testSet {
 | 
			
		||||
| 
						 | 
				
			
			@ -231,7 +231,7 @@ func BenchmarkTruncIndexGet500(b *testing.B) {
 | 
			
		|||
	var testSet []string
 | 
			
		||||
	var testKeys []string
 | 
			
		||||
	for i := 0; i < 500; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	index := NewTruncIndex([]string{})
 | 
			
		||||
	for _, id := range testSet {
 | 
			
		||||
| 
						 | 
				
			
			@ -254,7 +254,7 @@ func BenchmarkTruncIndexGet500(b *testing.B) {
 | 
			
		|||
func BenchmarkTruncIndexDelete100(b *testing.B) {
 | 
			
		||||
	var testSet []string
 | 
			
		||||
	for i := 0; i < 100; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
	for i := 0; i < b.N; i++ {
 | 
			
		||||
| 
						 | 
				
			
			@ -277,7 +277,7 @@ func BenchmarkTruncIndexDelete100(b *testing.B) {
 | 
			
		|||
func BenchmarkTruncIndexDelete250(b *testing.B) {
 | 
			
		||||
	var testSet []string
 | 
			
		||||
	for i := 0; i < 250; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
	for i := 0; i < b.N; i++ {
 | 
			
		||||
| 
						 | 
				
			
			@ -300,7 +300,7 @@ func BenchmarkTruncIndexDelete250(b *testing.B) {
 | 
			
		|||
func BenchmarkTruncIndexDelete500(b *testing.B) {
 | 
			
		||||
	var testSet []string
 | 
			
		||||
	for i := 0; i < 500; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
	for i := 0; i < b.N; i++ {
 | 
			
		||||
| 
						 | 
				
			
			@ -323,7 +323,7 @@ func BenchmarkTruncIndexDelete500(b *testing.B) {
 | 
			
		|||
func BenchmarkTruncIndexNew100(b *testing.B) {
 | 
			
		||||
	var testSet []string
 | 
			
		||||
	for i := 0; i < 100; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
	for i := 0; i < b.N; i++ {
 | 
			
		||||
| 
						 | 
				
			
			@ -334,7 +334,7 @@ func BenchmarkTruncIndexNew100(b *testing.B) {
 | 
			
		|||
func BenchmarkTruncIndexNew250(b *testing.B) {
 | 
			
		||||
	var testSet []string
 | 
			
		||||
	for i := 0; i < 250; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
	for i := 0; i < b.N; i++ {
 | 
			
		||||
| 
						 | 
				
			
			@ -345,7 +345,7 @@ func BenchmarkTruncIndexNew250(b *testing.B) {
 | 
			
		|||
func BenchmarkTruncIndexNew500(b *testing.B) {
 | 
			
		||||
	var testSet []string
 | 
			
		||||
	for i := 0; i < 500; i++ {
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateRandomID())
 | 
			
		||||
		testSet = append(testSet, stringid.GenerateNonCryptoID())
 | 
			
		||||
	}
 | 
			
		||||
	b.ResetTimer()
 | 
			
		||||
	for i := 0; i < b.N; i++ {
 | 
			
		||||
| 
						 | 
				
			
			@ -357,7 +357,7 @@ func BenchmarkTruncIndexAddGet100(b *testing.B) {
 | 
			
		|||
	var testSet []string
 | 
			
		||||
	var testKeys []string
 | 
			
		||||
	for i := 0; i < 500; i++ {
 | 
			
		||||
		id := stringid.GenerateRandomID()
 | 
			
		||||
		id := stringid.GenerateNonCryptoID()
 | 
			
		||||
		testSet = append(testSet, id)
 | 
			
		||||
		l := rand.Intn(12) + 12
 | 
			
		||||
		testKeys = append(testKeys, id[:l])
 | 
			
		||||
| 
						 | 
				
			
			@ -382,7 +382,7 @@ func BenchmarkTruncIndexAddGet250(b *testing.B) {
 | 
			
		|||
	var testSet []string
 | 
			
		||||
	var testKeys []string
 | 
			
		||||
	for i := 0; i < 500; i++ {
 | 
			
		||||
		id := stringid.GenerateRandomID()
 | 
			
		||||
		id := stringid.GenerateNonCryptoID()
 | 
			
		||||
		testSet = append(testSet, id)
 | 
			
		||||
		l := rand.Intn(12) + 12
 | 
			
		||||
		testKeys = append(testKeys, id[:l])
 | 
			
		||||
| 
						 | 
				
			
			@ -407,7 +407,7 @@ func BenchmarkTruncIndexAddGet500(b *testing.B) {
 | 
			
		|||
	var testSet []string
 | 
			
		||||
	var testKeys []string
 | 
			
		||||
	for i := 0; i < 500; i++ {
 | 
			
		||||
		id := stringid.GenerateRandomID()
 | 
			
		||||
		id := stringid.GenerateNonCryptoID()
 | 
			
		||||
		testSet = append(testSet, id)
 | 
			
		||||
		l := rand.Intn(12) + 12
 | 
			
		||||
		testKeys = append(testKeys, id[:l])
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -127,7 +127,7 @@ var globalTestID string
 | 
			
		|||
// new directory.
 | 
			
		||||
func TestDirectory(templateDir string) (dir string, err error) {
 | 
			
		||||
	if globalTestID == "" {
 | 
			
		||||
		globalTestID = stringid.GenerateRandomID()[:4]
 | 
			
		||||
		globalTestID = stringid.GenerateNonCryptoID()[:4]
 | 
			
		||||
	}
 | 
			
		||||
	prefix := fmt.Sprintf("docker-test%s-%s-", globalTestID, GetCallerName(2))
 | 
			
		||||
	if prefix == "" {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue