0

そのページのサンプル Java コードを使用して、 OpenSocial 0.7 署名付きリクエストを検証しようとしています。このように動作するはずだと思いますが、それでも signature_invalid エラーが発生します。

主な検証コード:

 // NOTE: req = HttpServletRequest

 // check for hyves
 if (!"hyves.nl".equals(req.getParameter("oauth_consumer_key"))) {
  throw new RuntimeException("Only hyves supported");
 }

 // update hyves' certificate
 getHyvesCert(req.getParameter("xoauth_signature_publickey"));

 // construct message object
 OAuthMessage oaMessage = new OAuthMessage(req.getMethod(), getRequestUrl(req), getParameters(req));

 // validate message
 // (will throw exception if invalid)
 new SimpleOAuthValidator().validateMessage(oaMessage, new OAuthAccessor(OAUTH_CONSUMER_HYVES));

OAUTH_CONSUMER_HYVES:

 private static final OAuthServiceProvider OAUTH_THIS = new OAuthServiceProvider(null, null, null);
 private static final OAuthConsumer OAUTH_CONSUMER_HYVES = new OAuthConsumer(null, "hyves.nl", null, OAUTH_THIS);

getHyvesCert:

 public void getHyvesCert(String name) {

  synchronized(certLoadLock) {

  // in reality this is code that downloads the certificate
  // with the specified name, but this is the result
  hyvesCert = "---BEGIN CERTIFICATE---- etc...";

  OAUTH_CONSUMER_HYVES.setProperty(RSA_SHA1.X509_CERTIFICATE, hyvesCert);

  }   

 }

メソッドgetRequestUrlgetParametershere から直接コピーされます

4

1 に答える 1

1

問題が見つかりました。getRequestUrl()Tomcat が nginx プロキシの背後にあるため、間違った URL が返されました。したがって、送信者は URL " http://example.com/bla " を使用してリクエストに署名しますが、サーバーは " http://example.com:8080/bla " を使用してそれを検証していました。

于 2010-10-19T12:52:50.313 に答える