我想使用 TLS 创建一个简单的安全客户端/服务器。我已按照官方文档的说明进行操作。但我不知道如何使用 openssl 创建自签名证书(对我不起作用)。
这里的代码:
服务器.js
const tls = require('tls');
const fs = require('fs');
const options = {
key: fs.readFileSync('server-key.pem'),
cert: fs.readFileSync('server-cert.pem'),
// This is necessary only if using the client certificate authentication.
requestCert: true,
// This is necessary only if the client uses the self-signed certificate.
ca: [ fs.readFileSync('client-cert.pem') ]
};
const server = tls.createServer(options, (socket) => {
console.log('server connected',
socket.authorized ? 'authorized' : 'unauthorized');
socket.write('welcome!\n');
socket.setEncoding('utf8');
socket.pipe(socket);
});
server.listen(8000, () => {
console.log('server bound');
}); …Run Code Online (Sandbox Code Playgroud) 从标准库URL.Query()到结构直接映射会很棒。
Query() 返回类似的地图:
map[a:[aaaa] b:[bbbb] c:[cccc]]
该结构看起来像:
type Thing struct {
A string
B string
C string
}
Run Code Online (Sandbox Code Playgroud)
GET不太可能重复参数)我想要做什么,给定一个 URL 并使用 Golang 截取网站的屏幕截图。我搜索了结果,但没有得到任何结果。谁能帮帮我吗。
Using github.com/knq/chromedp, a go package to drive web browsers using Chrome Debugging Protocol, I can navigate to webpages, update forms and submit forms, but I need to retrieve a HTTP response body and haven't figured out how to yet. I'd like to be able to retrieve the HTTP response body for a JSON response (not HTML).
From looking in the code, it seems the HTTP response body is in the CachedResponse.Body property:
And that it should be accessible …
我正在创建一个使用 [chromedp][1] 的应用程序
如何检查页面中是否存在某个元素?
我尝试使用cdp.WaitVisible(),但它没有给我我想要的东西。
我需要这个,这样我就可以判断应用程序是否会做一件事或另一件事。
对于这个例子,假设我需要知道搜索输入是否存在
我怎样才能做到这一点?
[1]: https: //github.com/knq/chromedp
package main
import (
"context"
"fmt"
"io/ioutil"
"log"
"time"
cdp "github.com/knq/chromedp"
cdptypes "github.com/knq/chromedp/cdp"
)
func main() {
var err error
// create context
ctxt, cancel := context.WithCancel(context.Background())
defer cancel()
// create chrome instance
c, err := cdp.New(ctxt, cdp.WithLog(log.Printf))
if err != nil {
log.Fatal(err)
}
// run task list
var site, res string
err = c.Run(ctxt, googleSearch("site:brank.as", "Easy Money Management", &site, &res))
if err != nil { …Run Code Online (Sandbox Code Playgroud) 我有一个 nodejs 项目,其中包含许多请求并由 apiDoc 详细记录,我想从中创建一个 Postman 集合!
> example:
/**
* @api {GET} config/updates Updates - Get the latest event updates
* @apiGroup Config service
* @apiDescription This api endpoint provides the latest updates that need to be fetched by the client. It provides
* an array of events, based on either the latestupdate (timestamp) param, or a configured interval (currently default to 1 minute.
...
..
*/
Run Code Online (Sandbox Code Playgroud)
可以从 apiDoc 创建邮递员集合吗?
元数据库 ( https://metabase.com/ ) 数据资源管理器 Web UI 能够创建查询,他们称之为具有各种过滤器的问题。查询结果可以通过多种方式可视化,包括表格和图表。表格结果也可以以 JSON 格式下载。有没有办法通过元数据库 REST API 检索 JSON?
我已尝试使用数据资源管理器 URL 中的 ID 元数据库 API 参考中的一些端点,但没有成功。
API 参考:https : //github.com/metabase/.../api-documentation.md
我想以与在此处完成的方式类似的方式验证openapi规范:http://bigstickcarpet.com/swagger-parser/www/index.html 但不同之处在于我使用GO来编写工具代码并且只使用CLI .
我想用这个:
https://github.com/go-openapi/validate
但主要问题是文档几乎不存在.我来到这里寻找以前可能使用过这个库的人的帮助,并且可以给我一个MINIMAL示例,发送一个包含类似规范的文件,并让这个库以与在线Swagger验证器类似的方式抛出所有错误或警告.
我已经可以读取文件并对其中的字段进行一些手动验证,但当然这不是我需要做的,而只是一个样本.
另外,作为第二个问题,我想在他们的GitHub回购中发布同样的问题,但我明白了:
我不知道如何"审查"这些指导方针,所以我可以发表我的问题.
func validate_spec(spec string) []validator_error {
// RULES HERE. Now I am hardcoding since this is just a dummy app. On the real app we will need to use goapenapi plus a schema validator
var errors []validator_error
name_regex, _ := regexp.Compile("^[a-zA-Z]+[ ][a-zA-Z]+")
// Validate _.name field
if ( ! gjson.Get(spec, "name").Exists() ) {
n := validator_error{Path: "_.name", Message: "Does not exist!"}
errors = append(errors,n)
}
if gjson.Get(spec, "name").Exists() …Run Code Online (Sandbox Code Playgroud) 我可以选择支持客户证书。这就是为什么我设置Client certificates到AcceptIIS上。这适用于大多数计算机。但是,在某些计算机上,IIS返回500。可以通过设置Client certificates为Ignore(不是我的选择)或通过设置Negotiate Client Certificate为Enabled(可以通过将in netsh http add ...更改DefaultFlags为2来解决)HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\HTTP\Parameters\SslBindingInfo\0.0.0.0:443\。在IIS管理器中进行更改?)。虽然(启用)此设置听起来很合理,但仅看名字我就不明白为什么在某些机器上需要它,但在其他机器上不需要...
iis ssl client-certificates iis-7.5 ssl-client-authentication
我正在使用以下代码创建令牌
token := jwt.NewWithClaims(jwt.SigningMethodHS256, jwt.StandardClaims{
Subject: string(user.Id),
})
tokenString, err := token.SignedString([]byte("secret"))
Run Code Online (Sandbox Code Playgroud)
并尝试使用以下代码解析它们
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, UnauthorizedError
}
return []byte("secret"), nil
})
if err != nil {
return -1, UnauthorizedError
}
if !token.Valid {
return -1, UnauthorizedError
}
claims, ok := token.Claims.(jwt.MapClaims)
if !ok {
return -1, UnauthorizedError
}
logrus.Info(claims)
Run Code Online (Sandbox Code Playgroud)
为什么我不能将我的声明转换为 StandardClaims 并访问 claim.Subject?