Как устранить ошибку Google PHP SDK OpenSSL: ASN1_get_object:header слишком длинный

У меня возникли проблемы с тем, чтобы Google php sdk принял загрузку файла p12 напрямую (фактически дважды) из Google Dev Console. Все соответствующие разрешения API должны быть на месте.

Файл доступен для чтения сервером, и мой хост (MediaTemple Grid Server) говорит, что ничто не должно блокировать это с их стороны.

Это проблема в собственном SDK Google или я что-то не так делаю?

Ошибка PHP Неустранимая ошибка: необработанное исключение «Google_Auth_Exception» с сообщением «Невозможно проанализировать файл p12. Это файл .p12? Верен ли пароль? Ошибка OpenSSL: ошибка: 0D07207B: процедуры кодирования asn1: ASN1_get_object: слишком длинный заголовок

[26-Mar-2015 12:39:52 America/New_York] PHP Fatal error:  Uncaught exception 'Google_Auth_Exception' with message 'Unable to parse the p12 file.  Is this a .p12 file?  Is the password correct?  OpenSSL error: error:0D07207B:asn1 encoding routines:ASN1_get_object:header too long' in /vendor/google/apiclient/src/Google/Signer/P12.php:53
Stack trace:
#0 /vendor/google/apiclient/src/Google/Auth/AssertionCredentials.php(130): Google_Signer_P12->__construct('0\xEF\xBF\xBD\x06\xEF\xBF\xBD\x02\x01\x030\xEF\xBF\xBD...', 'notasecret')
#1 /vendor/google/apiclient/src/Google/Auth/AssertionCredentials.php(107): Google_Auth_AssertionCredentials->makeSignedJwt(Array)
#2 /vendor/google/apiclient/src/Google/Auth/OAuth2.php(306): Google_Auth_AssertionCredentials->generateAssertion()
#3 /vendor/google/apiclient/src/Google/Auth/OAuth2.php(233): Google_Auth_OAuth2->refreshTokenWithAssertion()
#4 /vendor/google/apiclient/src/Google/Service/Resource.php(208): Google_Auth_OAuth2->sign(Object(Google_Http_Request))
#5 /vendor/google/apiclient/src/Google/Service/Datastore.php(232): Google_Service_Resource->call('runQuery', Array, 'Google_Service_...')
#6 /vendor/tomwalder/php-gds/src/GDS/Gateway.php(360): Google_Service_Datastore_Datasets_Resource->runQuery('SomeName', Object(Google_Service_Datastore_RunQueryRequest))
#7 /vendor/tomwalder/php-gds/src/GDS/Gateway.php(305): GDS\Gateway->executeQuery(Object(Google_Service_Datastore_GqlQuery))
#8 /vendor/tomwalder/php-gds/src/GDS/Store.php(270): GDS\Gateway->gql('SELECT * FROM `...', NULL)
#9 /datastore_test/simple.php(28): GDS\Store->fetchOne()
#10 {main}
  thrown in /vendor/google/apiclient/src/Google/Signer/P12.php on line 53

Обновить ... да, файлы были бы полезны. :)

config.php

<?php
/**
 * Template Configuration file for php-gds examples
 *
 * @author Tom Walder <[email protected]>
 */
define('GDS_APP_NAME', 'NAME');
define('GDS_KEY_FILE_PATH', dirname(__FILE__) . '/google-generated-keyname.p12');
define('GDS_SERVICE_ACCOUNT_NAME', 'NAME-No');
define('GDS_DATASET_ID', 'DataStore');

$certs = array();
$pkcs12 = file_get_contents( GDS_KEY_FILE_PATH );
// No password
openssl_pkcs12_read( $pkcs12, $certs, "notasecret" );
//echo $certs['cert'];

$data[0] = $certs['cert'];
$data[1] = 'notasecret';

P12.php от Google

// If the private key is provided directly, then this isn't in the p12
// format. Different versions of openssl support different p12 formats
// and the key from google wasn't being accepted by the version available
// at the time.
if (!$password && strpos($p12, "-----BEGIN RSA PRIVATE KEY-----") !== false) {
  $this->privateKey = openssl_pkey_get_private($p12);
} else {
  // This throws on error
  $certs = array();
  if (!openssl_pkcs12_read($p12, $certs, $password)) {
    throw new Google_Auth_Exception(
        "Unable to parse the p12 file.  " .
        "Is this a .p12 file?  Is the password correct?  OpenSSL error: " .
        openssl_error_string()
    );
  }
  // TODO(beaton): is this part of the contract for the openssl_pkcs12_read
  // method?  What happens if there are multiple private keys?  Do we care?
  if (!array_key_exists("pkey", $certs) || !$certs["pkey"]) {
    throw new Google_Auth_Exception("No private key found in p12 file.");
  }
  $this->privateKey = openssl_pkey_get_private($certs['pkey']);
}

Относится к Получение невозможности анализа файл p12... Ошибка с google-api-php-client


person m-torin    schedule 26.03.2015    source источник
comment
вам нужно опубликовать свой код, прежде чем кто-либо сможет помочь вам отладить его.   -  person DaImTo    schedule 26.03.2015
comment
да, это явно помогло бы.   -  person m-torin    schedule 26.03.2015
comment
все еще не повезло после публикации вашего кода?   -  person davidvnog    schedule 09.08.2016