mirror of
				https://github.com/caddyserver/caddy.git
				synced 2025-10-31 02:27:19 -04:00 
			
		
		
		
	Merge pull request #514 from upsuper/fix-user-key-perm
letsencrypt: Fix perm of user key
This commit is contained in:
		
						commit
						6e340cb1d6
					
				| @ -25,6 +25,7 @@ func saveRSAPrivateKey(key *rsa.PrivateKey, file string) error { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | 	keyOut.Chmod(0600) | ||||||
| 	defer keyOut.Close() | 	defer keyOut.Close() | ||||||
| 	return pem.Encode(keyOut, &pemKey) | 	return pem.Encode(keyOut, &pemKey) | ||||||
| } | } | ||||||
|  | |||||||
| @ -6,6 +6,7 @@ import ( | |||||||
| 	"crypto/rsa" | 	"crypto/rsa" | ||||||
| 	"crypto/x509" | 	"crypto/x509" | ||||||
| 	"os" | 	"os" | ||||||
|  | 	"runtime" | ||||||
| 	"testing" | 	"testing" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| @ -28,13 +29,26 @@ func TestSaveAndLoadRSAPrivateKey(t *testing.T) { | |||||||
| 		t.Fatal("error saving private key:", err) | 		t.Fatal("error saving private key:", err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	// it doesn't make sense to test file permission on windows | ||||||
|  | 	if runtime.GOOS != "windows" { | ||||||
|  | 		// get info of the key file | ||||||
|  | 		info, err := os.Stat(keyFile) | ||||||
|  | 		if err != nil { | ||||||
|  | 			t.Fatal("error stating private key:", err) | ||||||
|  | 		} | ||||||
|  | 		// verify permission of key file is correct | ||||||
|  | 		if info.Mode().Perm() != 0600 { | ||||||
|  | 			t.Error("Expected key file to have permission 0600, but it wasn't") | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	// test load | 	// test load | ||||||
| 	loadedKey, err := loadRSAPrivateKey(keyFile) | 	loadedKey, err := loadRSAPrivateKey(keyFile) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		t.Error("error loading private key:", err) | 		t.Error("error loading private key:", err) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	// very loaded key is correct | 	// verify loaded key is correct | ||||||
| 	if !rsaPrivateKeysSame(privateKey, loadedKey) { | 	if !rsaPrivateKeysSame(privateKey, loadedKey) { | ||||||
| 		t.Error("Expected key bytes to be the same, but they weren't") | 		t.Error("Expected key bytes to be the same, but they weren't") | ||||||
| 	} | 	} | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user