-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
Version issue with age-encrypted sops files #17
Comments
I played with this some more and was able to get it. I needed to extract the base64 encoded key: function getEncryptionKeyForRecipient(
sopsFile: string,
privateAgeKey: string
) {
const { Decrypter } = await age();
const doc = await loadSopsFile(sopsFile);
if (!Array.isArray(doc?.sops?.age)) {
throw new Error("missing sops age metadata");
}
const sopsAgeConfig = doc.sops.age;
const pubKey = await getPublicAgeKey(privateAgeKey);
const { enc } = sopsAgeConfig.find(
(config: SopsAgeConfig) => config.recipient === pubKey
);
if (!enc) {
throw new Error("no matching recipient found in age config");
}
const decrypter = new Decrypter();
decrypter.addIdentity(privateAgeKey);
const regex =
/-----BEGIN AGE ENCRYPTED FILE-----\s*([\s\S]*?)\s*-----END AGE ENCRYPTED FILE-----/;
const matches = enc.match(regex);
if (!(matches && matches[1])) {
throw new Error("unable to extract age encryption key");
}
const base64String = matches[1].trim();
const encrypted = Buffer.from(base64String, "base64");
const decryptionKey = decrypter.decrypt(encrypted, "uint8array");
return decryptionKey;
} I'm surprised that I couldn't use the whole |
I ended up making an npm package to work with sops and age in TS/JS: https://github.com/humphd/sops-age Thanks for making this! |
Hello! Sorry for the late response but I was apparently not "Watching" this repository. No idea how that happened. It's not you, the armored encoding (PEM with Thank you for working on this and making sops-age. |
@FiloSottile I hate how GitHub does this, so you end up missing notifications for your own repos (happens to me a lot). Thanks for the encouragement! |
Thank you for making this. I couldn't believe it when I went looking for a TS age implementation, and lo and behold, you had made an official one. Amazing!
My current use case is being able to decrypt pieces of an age-encrypted sops file in JS. We
Here's an example of the kind of thing I want to parse, where I need to decrypt the
value
key, and my AGE public key is listed as arecipient
:Here's my first attempt to get that decryption key:
When I run this, I get the following error:
Which seems to be
typage/lib/format.ts
Line 109 in d074454
On my system I'm using:
Do I need to pass more info in order to be able to do this? Use a different version somehow? Or maybe it's not possible?
Thanks for helping me understand what is and isn't possible.
The text was updated successfully, but these errors were encountered: