Exemplo n.º 1
0
        public void HashedUserTest()
        {
            IOpenPgpKeySearch pgpKeys = new OpenPgpKeySearch();

            var hu = pgpKeys.GetHashedUserId("me");

            Assert.Equal("s8y7oh5xrdpu9psba3i5ntk64ohouhga", hu);
        }
Exemplo n.º 2
0
        public async Task SearchHttpKeyserverProtocol()
        {
            IOpenPgpKeySearch pgpKeys = new OpenPgpKeySearch();

            var email = "*****@*****.**";
            var key   = await pgpKeys.SearchHttpKeyServer(email);

            Assert.NotNull(key);

            Utils.CheckFingerprint(key, "4805b5106ca0eab809e16b798bfc4819e62f4977");
        }
Exemplo n.º 3
0
        public async Task SearchErrorTest()
        {
            IOpenPgpKeySearch pgpKeys = new OpenPgpKeySearch();

            await Assert.ThrowsAsync <FormatException>(() => pgpKeys.SearchWebKeyDirectory("notanaddress"));

            var inexistantEmail = "*****@*****.**";
            var inexistantKey   = await pgpKeys.SearchWebKeyDirectory(inexistantEmail);

            Assert.Null(inexistantKey);

            inexistantKey = await pgpKeys.SearchHttpKeyServer(inexistantEmail);

            Assert.Null(inexistantKey);
        }
Exemplo n.º 4
0
        private static WkdSavedKeys LoadPublicKeys(IEnumerable <PgpPublicKey> publicKeys, OpenPgpKeyManagement?keyManagement = null)
        {
            var context   = new WkdSavedKeys();
            var keySearch = new OpenPgpKeySearch();

            if (keyManagement == null)
            {
                keyManagement = new OpenPgpKeyManagement();
            }

            foreach (var key in publicKeys)
            {
                foreach (string userId in key.GetUserIds())
                {
                    MailAddress mailAddress;
                    try
                    {
                        mailAddress = new MailAddress(userId);
                    }
                    catch (FormatException)
                    {
                        // UserId is not a mail adress, we don't save it
                        continue;
                    }

                    var host = mailAddress.Host;
                    Dictionary <string, string> hostDic;
                    if (!context.PublicKeys.TryGetValue(host, out hostDic))
                    {
                        hostDic = new Dictionary <string, string>();
                        context.PublicKeys.Add(host, hostDic);
                    }

                    var user = keySearch.GetHashedUserId(mailAddress.User);

                    if (hostDic.ContainsKey(user))
                    {
                        // we already have a public key for this e-mail address
                        continue;
                    }
                    var keyString = keyManagement.Export(key);
                    hostDic.Add(user, keyString);
                }
            }

            return(context);
        }