简体   繁体   English

如何针对私钥验证.Onion域

[英]How to verify a .Onion domain against a private key

I am working on a project that will basically sell .Onion (TOR) domain names. 我正在从事一个基本上将出售.Onion(TOR)域名的项目。 The process of generating the domains is similar to mining bitcoins - RSA private keys are generated en mass and if one randomly matches something in my wordlist - then it gets saved off somewhere and added to a database. 生成域的过程类似于挖掘比特币-RSA私钥是批量生成的,如果一个人随机匹配我的单词列表中的某个内容-则它会保存到某个地方并添加到数据库中。

The problem here is that this is still a slow process to do solo - so in order for me to try and make it a collaborate exercise - I want to create an online API / Rest API that will allow people to upload their domains and private keys for them to sell on the site. 这里的问题是,这仍然是一个很慢的独奏过程-因此,为了让我尝试使其成为一个协作练习-我想创建一个在线API / Rest API,该API将允许人们上传其域和私钥供他们在网站上出售。

The problem is - I don't quite know how to verify their domain name against the private key. 问题是-我不太了解如何根据私钥验证其域名。

Eg: They would be providing a domain like 例如:他们将提供一个类似

abcdabcdabcdabcd.onion abcdabcdabcdabcd.onion

and the key would be: -----BEGIN RSA PRIVATE KEY----- MIICXQIBAAKBgQCb+wlPxR8VoUJsYcEFsPX+LfB3jorW9QlH1N38itQvMs0RyTCB +c7hfYQH2f8Z67lobWvveYct51ykhB8n3AluMYIF3OxGlmQJuMIFQmKFryLexzPj LEPREB7+KmeL9Sx1sL4a2Z0qJL4501Ij0T5C3cDEMOvUQBpBttpuUbj1RQIEZTIY AQKBgBwWDEMOYKaSO17xJRuf32CDYJcDKtkJ1GlWROHxREo68J+74DqF55rnoYl/ 4OkfjUMA2WjjjASVRmviBD79vni3eB9MFNzDEMOYa6EIyo1vDEMOzEnfrszkPGEj vOCHbDiG/FlZsCKsADEMOEAuAUQ3W8669Du4FrO9/al+1IudhAkEAy+KBk8HFsO8Z UttdlsLt8//l+NbEMmWF/I588EGyYWUuPUVJd5Xv6iSaDMdecjeW/xf4Wja5C91n lCfb/lxhsQJBAMPZ2fzcUpyKhk6JretSyoq0iVQCO5Pn/0QwTwRUbKreXnnVBYY+ uco2ocfRwsm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NGADEMO9F5KhlDr1wwSQqnNccDX5 N5vnlhJ/0DGxIMm/bP1ZPUK4/bmvKjNYd7D8zuz2cPor -----END RSA PRIVATE KEY-----

Could someone point me in the direction of some .Net code that can take a private key, and verify that the domain also provided is authentic? 有人可以指出一些可以带私钥的.Net代码的方向,并验证所提供的域是否真实吗? https://github.com/lachesis/scallion This github project (one of the tools I use - has the code to 'generate' the domains and private keys - I am just not sure how to perform the verification after the fact) https://github.com/lachesis/scallion这个github项目(我使用的工具之一-具有“生成”域​​和私钥的代码-我只是不确定在事实发生后如何执行验证)

Never got an answer for this, but I did find a way, using Scallions on source code to verify a Private Key against an Onion Address. 从来没有得到答案,但是我确实找到了一种方法,在源代码上使用Scallions来针对洋葱地址验证私钥。

RSAWrapper rsaWrapper = new RSAWrapper("d:\\pk.txt");
Console.WriteLine(rsaWrapper.OnionHash);

Not ideal - as it requires the private key. 不理想-因为它需要私钥。 Inside the RSAWrapper - it does some unsafe code to do 'something' to the public key to determine a DER encoded value. 在RSAWrapper内部-它执行一些不安全的代码来对公钥执行“某些操作”以确定DER编码值。 This is the important part of getting the onion address. 这是获得洋葱地址的重要部分。

public string OnionHash
        {
            get {
                return tobase32str(this.get_der_hash(),10);
            }
        }

private byte[] get_der_hash()
        {
            var sha1 = new System.Security.Cryptography.SHA1Managed();
            return sha1.ComputeHash(this.DER);
            //return tobase32str(hash);
        }


public byte[] DER {
            get {
                byte[] der;
                int buf_size = Rsa.Size + 100;
                int size = 0;
                unsafe // must be a better way to do this!
                {
                    IntPtr hglob = Marshal.AllocHGlobal(buf_size);
                    void* ptr = hglob.ToPointer();
                    void** ptr2 = &ptr;

                    size = Native.i2d_RSAPublicKey(Rsa.Handle, (byte**)ptr2);
                    if(size > buf_size)
                        throw new IndexOutOfRangeException("DER was too large!");

                    der = new byte[size];
                    Marshal.Copy(hglob,der,0,size);
                    Marshal.FreeHGlobal(hglob);
                }
                return der;
            }
        }

Edit - Woot : Looks like the RSAWrapper class is very cohesive and modular. 编辑-Woot:看起来RSAWrapper类非常具有凝聚力和模块化。 I was able to copy it out - it only needs access to the OpenSSL library, and it also has an RSA.FromPublicKey(string s); 我能够将其复制出-它只需要访问OpenSSL库,并且还具有RSA.FromPublicKey(string s);。 method for creating the RSA. 创建RSA的方法。

So now, I am able to do 所以现在我可以

    RSAWrapper rsaWrapper = new RSAWrapper("d:\\pubkey.txt", true);
    Console.WriteLine(rsaWrapper.OnionHash);

Took a few months - but got a better answer than I set out to get. 花了几个月的时间-但得到的答案比我打算得到的更好。 Now I can take public keys, and verify that the Onion address matches the public key. 现在,我可以使用公共密钥,并验证洋葱地址是否与公共密钥匹配。 This would verify ownership of an Onion address, without the risk of having to send a private key across the network. 这将验证洋葱地址的所有权,而不必承担通过网络发送私钥的风险。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM