首页 > 后端开发 > Golang > 正文

golang中的持久隐藏服务

WBOY
发布: 2024-02-09 12:33:09
转载
906人浏览过

golang中的持久隐藏服务

php小编新一带你一起探索golang中的持久隐藏服务。Golang是一种高效的编程语言,以其卓越的性能和并发性而闻名。在这个快节奏的互联网时代,隐藏服务成为了许多应用程序的重要组成部分。它们提供了一种安全且可靠的方式,使应用程序能够长时间运行,同时隐藏其内部细节。本文将介绍golang中如何实现持久隐藏服务,并探讨其在实际应用中的应用场景和优势。无论您是初学者还是有经验的开发者,都能从中获得有益的知识和实践经验。让我们一起来探索这个有趣的话题吧!

问题内容

我正在尝试使用 github.com/cretz/bine/tor 在 golang 中托管一个隐藏服务。 但每次我启动程序时,都会启动一个新的隐藏服务(带有新的 .onion 地址),而不是之前的隐藏服务。

这是我使用的代码

package main

import (
    "context"
    "fmt"
    "github.com/cretz/bine/tor"
    "log"
    "net/http"
    "time"
)

func main() {
    // Start tor with default config
    fmt.Println("Starting and registering onion service, please wait a couple of minutes...")
    t, err := tor.Start(nil, nil)
    if err != nil {
        log.Panicf("Unable to start Tor: %v", err)
    }
    defer t.Close()
    // Wait at most a few minutes to publish the service
    listenCtx, listenCancel := context.WithTimeout(context.Background(), 3*time.Minute)
    defer listenCancel()
    // Create a v3 onion service
    onion, err := t.Listen(listenCtx, &tor.ListenConf{Version3: true, RemotePorts: []int{80}})
    if err != nil {
        log.Panicf("Unable to create onion service: %v", err)
    }
    defer onion.Close()
    fmt.Printf("Open Tor browser and navigate to http://%v.onion\n", onion.ID)
    fmt.Println("Press enter to exit")
    // Serve the current folder from HTTP
    errCh := make(chan error, 1)
    go func() { errCh <- http.Serve(onion, http.FileServer(http.Dir("."))) }()
    // End when enter is pressed
    go func() {
        fmt.Scanln()
        errCh <- nil
    }()
    if err = <-errCh; err != nil {
        log.Panicf("Failed serving: %v", err)
    }
}


登录后复制

我尝试强制程序使用相同的 DataDir

t, err := tor.Start(nil, &tor.StartConf{DataDir: "data-dir"})

立即学习go语言免费学习笔记(深入)”;

但这行不通。

解决方法

您需要创建并存储一个密钥,然后将其传递给 ListenConf:

参见:https://github.com/cretz /bine/blob/master/tor/listen.go#L56

注意:

您正在使用的库提供了执行此操作的函数。

参见:https://github.com /cretz/bine/blob/b9d31d9c786616742e39a121b60522e803e96731/torutil/ed25519/ed25519.go#L132

执行此操作一次并保存 privateKeyString:

keyPair, _ := ed25519.GenerateKey()
privateKeyString := hex.EncodeToString(keyPair.PrivateKey())
登录后复制

然后在您的服务器代码中:

privateKeyBytes, _ := hex.DecodeString(privateKeyString)
privateKey := ed25519.PrivateKey(privateKeyBytes)
lc := &tor.ListenConf{
    Key: privateKey,
    Version3: true,
    RemotePorts: []int{80}
}
登录后复制

以上就是golang中的持久隐藏服务的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
相关标签:
来源:stackoverflow网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号