BundleConfig first signs the config with the root private key, ensuring the authenticity, then encrypts the message using the bytes of the root public key as the shared key, offering some level of privacy. (assuming the root public key is not shared widely)
(config string, rootKey NyPrivateKey)
| 66 | |
| 67 | // BundleConfig first signs the config with the root private key, ensuring the authenticity, then encrypts the message using the bytes of the root public key as the shared key, offering some level of privacy. (assuming the root public key is not shared widely) |
| 68 | func BundleConfig(config string, rootKey NyPrivateKey) (string, error) { |
| 69 | cfg := CentralCfg{} |
| 70 | err := yaml.Unmarshal([]byte(config), &cfg) |
| 71 | if err != nil { |
| 72 | return "", err |
| 73 | } |
| 74 | err = CentralConfigValidator(&cfg) |
| 75 | if err != nil { |
| 76 | return "", err |
| 77 | } |
| 78 | cfg.Timestamp = time.Now().UnixNano() |
| 79 | |
| 80 | plainText, err := yaml.Marshal(cfg) |
| 81 | |
| 82 | bundle, err := SignBundle(plainText, rootKey) |
| 83 | if err != nil { |
| 84 | return "", err |
| 85 | } |
| 86 | pub := rootKey.Pubkey() |
| 87 | bundle, err = SealBundle(bundle, pub[:]) |
| 88 | if err != nil { |
| 89 | return "", err |
| 90 | } |
| 91 | |
| 92 | return base64.StdEncoding.EncodeToString(bundle), nil |
| 93 | } |
| 94 | |
| 95 | func UnbundleConfig(bundleStr string, pubKey NyPublicKey) (*CentralCfg, error) { |
| 96 | bundle, err := base64.StdEncoding.DecodeString(bundleStr) |