Esempio n. 1
1
Poco::AutoPtr<Poco::XML::Document> Twitter::invoke(const std::string& httpMethod, const std::string& twitterMethod, Poco::Net::HTMLForm& form)
{
    // Create the request URI.
    // We use the XML version of the Twitter API.
    Poco::URI uri(_uri + twitterMethod + ".xml");
    std::string path(uri.getPath());

    Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
    Poco::Net::HTTPRequest req(httpMethod, path, Poco::Net::HTTPMessage::HTTP_1_1);

    // Add username and password (HTTP basic authentication) to the request.
    Poco::Net::HTTPBasicCredentials cred(_username, _password);
    cred.authenticate(req);

    // Send the request.
    form.prepareSubmit(req);
    std::ostream& ostr = session.sendRequest(req);
    form.write(ostr);

    // Receive the response.
    Poco::Net::HTTPResponse res;
    std::istream& rs = session.receiveResponse(res);

    // Create a DOM document from the response.
    Poco::XML::DOMParser parser;
    parser.setFeature(Poco::XML::DOMParser::FEATURE_FILTER_WHITESPACE, true);
    parser.setFeature(Poco::XML::XMLReader::FEATURE_NAMESPACES, false);
    Poco::XML::InputSource source(rs);
    Poco::AutoPtr<Poco::XML::Document> pDoc = parser.parse(&source);

    // If everything went fine, return the XML document.
    // Otherwise look for an error message in the XML document.
    if (res.getStatus() == Poco::Net::HTTPResponse::HTTP_OK)
    {
        return pDoc;
    }
    else
    {
        std::string error(res.getReason());
        Poco::AutoPtr<Poco::XML::NodeList> pList = pDoc->getElementsByTagName("error");
        if (pList->length() > 0)
        {
            error += ": ";
            error += pList->item(0)->innerText();
        }
        throw Poco::ApplicationException("Twitter Error", error);
    }
}
OSStatus SecKeychainItemSetAccessWithPassword(SecKeychainItemRef itemRef, SecAccessRef accessRef, UInt32 passwordLength, const void * password)
{
    BEGIN_SECKCITEMAPI

    OSStatus result;

    // try to unlock the keychain with this password first
    SecKeychainRef kc = NULL;
    result = SecKeychainItemCopyKeychain(__itemImplRef, &kc);
    if(!result) {
        SecKeychainUnlock(kc, passwordLength, password, true);
        if(kc) {
            CFRelease(kc);
        }
    }

    // Create some credentials with this password
    CssmAutoData data(Allocator::standard(), password, passwordLength);
    AclFactory::PassphraseUnlockCredentials cred(data, Allocator::standard());

    Access::required(accessRef)->editAccess(*aclBearer(reinterpret_cast<CFTypeRef>(__itemImplRef)), true, cred.getAccessCredentials());
    ItemImpl::required(itemRef)->postItemEvent (kSecUpdateEvent);

    END_SECKCITEMAPI
}
Esempio n. 3
0
ClientPtrType init(String host, String port)
{
    Aws::Client::ClientConfiguration config;
    config.region = "us-west-2";
    config.endpointOverride = host + ":" + port;
    config.scheme = Aws::Http::Scheme::HTTP;
    Aws::Auth::AWSCredentials cred(ACCESS_KEY_ID, SECRET_ACCESS_KEY);
    return Aws::MakeShared<Aws::S3::S3Client>("S3Client", cred, config);
}
Esempio n. 4
0
StringBuffer BasicAuthentication::getAuthenticationHeaders() {
    
    StringBuffer cred(username);  
    cred += ":";  
    cred += password;
    
    StringBuffer credB64;
    b64_encode(credB64, cred.c_str(), cred.length());
    return credB64;
}
Esempio n. 5
0
TCred TCred::Current() {
    TCred cred(geteuid(), getegid());

    cred.Groups.resize(getgroups(0, nullptr));
    if (getgroups(cred.Groups.size(), cred.Groups.data()) < 0) {
        L_ERR() << "Cannot get supplementary groups for " << cred.Uid << std::endl;
        cred.Groups.resize(1);
        cred.Groups[0] = cred.Gid;
    }

    return cred;
}
Esempio n. 6
0
void LoggingHandler::handleRequest(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response)
{
	bool reauth = true;
	if (request.hasCredentials())
	{
		std::string cred;
		std::string scheme;
		try
		{
			Poco::Net::HTTPBasicCredentials cred(request);
			std::string user = cred.getUsername();
			std::istringstream istr(cred.getPassword(), std::ios::binary);
			Poco::MD5Engine md5;
			Poco::DigestOutputStream dos(md5);
			Poco::StreamCopier::copyStream(istr, dos);
			dos.close();
			std::string pwd = Poco::DigestEngine::digestToHex(md5.digest());
			reauth = (pwd != _pwdHash || _user != user);
		}
		catch (...)
		{
			reauth = true;
		}
	}
	if (reauth)
	{
		response.requireAuthentication(TITLE);
		response.send();
		return;
	}
	Poco::Net::HTMLForm form(request);
	std::string offsetStr;
	Poco::Net::NameValueCollection::ConstIterator it = form.find(OFFSET);
	if (it != form.end())
		offsetStr = it->second;
	int offset(0);
	Poco::NumberParser::tryParse(offsetStr, offset);
	std::string numEntriesStr;
	it = form.find(NUMENTRIES);
	if (it != form.end())
		numEntriesStr = it->second;
	int numEntries = DEFAULT_NUMENTRIES;
	Poco::NumberParser::tryParse(numEntriesStr, numEntries);
	std::vector<Poco::Message> messages;
	_channel.getMessages(messages, offset, numEntries);
	displayMessages(messages, offset, numEntries, _channel.getCurrentSize(), response);
}
Esempio n. 7
0
bool SIPController::InitializeSIP (string SIPURL, string SIPREGISTRAR, string SIPREALM, string SIPUSER, string SIPPASSWD) {
	if (_SIP_EndPoint == 0) {
		if (_SIP_Status == SIPStatusNone || _SIP_Status == SIPStatusStop) {
			_SIP_Status = SIPStatusStarting;
			SendEvent(new SIPEvent(SIPStatusStarting));

			_Transport_Config.port = 0;

			_Account_Config.idUri = SIPURL;
			_Account_Config.regConfig.registrarUri = SIPREGISTRAR;
			AuthCredInfo cred("digest", SIPREALM, SIPUSER, 0, SIPPASSWD);
			_Account_Config.sipConfig.authCreds.push_back(cred);


			if (InitCPlusPlus() == false) {
				_SIP_Status = SIPStatusNone;
				SendEvent(new SIPEvent(SIPStatusError));
				return false;
			}
		}
	}

	return false;
}
Esempio n. 8
0
//
// Key encryption tests.
//
void keyBlobs()
{
	printf("* Keyblob encryption test\n");
    CssmAllocator &alloc = CssmAllocator::standard();
	ClientSession ss(alloc, alloc);
    
    DLDbIdentifier dbId1(ssuid, "/tmp/one", NULL);
	DBParameters initialParams1 = { 3600, false };
    
    // create a new database
	DbHandle db = ss.createDb(dbId1, NULL, NULL, initialParams1);
	detail("Database created");
	
	// establish an ACL for the key
	StringData theAclPassword("Strenge Geheimsache");
	AclEntryPrototype initialAcl;
	initialAcl.TypedSubject = TypedList(alloc, CSSM_ACL_SUBJECT_TYPE_PASSWORD,
		new(alloc) ListElement(theAclPassword));
	AclEntryInput initialAclInput(initialAcl);
    
    AutoCredentials cred(alloc);
    cred += TypedList(alloc, CSSM_SAMPLE_TYPE_PASSWORD,
        new(alloc) ListElement(theAclPassword));
    
    // generate a key
	const CssmCryptoData seed(StringData("Farmers' day"));
	FakeContext genContext(CSSM_ALGCLASS_KEYGEN, CSSM_ALGID_DES,
		&::Context::Attr(CSSM_ATTRIBUTE_KEY_LENGTH, 64),
		&::Context::Attr(CSSM_ATTRIBUTE_SEED, seed),
		NULL);
    KeyHandle key;
    CssmKey::Header header;
    ss.generateKey(db, genContext, CSSM_KEYUSE_ENCRYPT | CSSM_KEYUSE_DECRYPT,
        CSSM_KEYATTR_RETURN_REF | CSSM_KEYATTR_PERMANENT,
        /*cred*/NULL, &initialAclInput, key, header);
	detail("Key generated");
    
    // encrypt with the key
    StringData clearText("Yet another boring cleartext sample string text sequence.");
    StringData iv("Aardvark");
    CssmKey nullKey; memset(&nullKey, 0, sizeof(nullKey));
	FakeContext cryptoContext(CSSM_ALGCLASS_SYMMETRIC, CSSM_ALGID_DES,
		&::Context::Attr(CSSM_ATTRIBUTE_KEY, nullKey),
		&::Context::Attr(CSSM_ATTRIBUTE_INIT_VECTOR, iv),
		&::Context::Attr(CSSM_ATTRIBUTE_MODE, CSSM_ALGMODE_CBC_IV8),
		&::Context::Attr(CSSM_ATTRIBUTE_PADDING, CSSM_PADDING_PKCS1),
        &::Context::Attr(CSSM_ATTRIBUTE_ACCESS_CREDENTIALS, cred),
		NULL);
	CssmData cipherText;
	ss.encrypt(cryptoContext, key, clearText, cipherText);
	detail("Plaintext encrypted with original key");
    
    // encode the key and release it
    CssmData blob;
    ss.encodeKey(key, blob);
    ss.releaseKey(key);
    detail("Key encoded and released");
    
    // decode it again, re-introducing it
    CssmKey::Header decodedHeader;
    KeyHandle key2 = ss.decodeKey(db, blob, decodedHeader);
    detail("Key decoded");
    
    // decrypt with decoded key
    CssmData recovered;
    ss.decrypt(cryptoContext, key2, cipherText, recovered);
    assert(recovered == clearText);
    detail("Decoded key correctly decrypts ciphertext");
    
    // check a few header fields
    if (!memcmp(&header, &decodedHeader, sizeof(header))) {
        detail("All header fields match");
    } else {
        assert(header.algorithm() == decodedHeader.algorithm());
        assert(header.blobType() == decodedHeader.blobType());
        assert(header.blobFormat() == decodedHeader.blobFormat());
        assert(header.keyClass() == decodedHeader.keyClass());
        assert(header.attributes() == decodedHeader.attributes());
        assert(header.usage() == decodedHeader.usage());
        printf("Some header fields differ (probably okay)\n");
    }
    
    // make sure we need the credentials (destructive)
    memset(&cred, 0, sizeof(cred));
    try {
        ss.decrypt(cryptoContext, key2, cipherText, recovered);
        error("RESTORED ACL FAILS TO RESTRICT");
    } catch (CssmError &err) {
        detail(err, "Restored key restricts access properly");
    }
}
Esempio n. 9
0
void mainwindow::setdmscene()
{

    QRectF dmbounds(0,0,619,438);
    scene=new QGraphicsScene(dmbounds,this);
    QFont sfont("Bitstream Vera Serif",10);
    sfont.setBold(true);
    QFont sfont2("Bitstream Vera Serif",11);
    sfont2.setBold(true);

    QPixmap pic("./pic/bpicrz.png");
    pix = new QGraphicsPixmapItem(pic);
    pix->setOffset(QPointF(0,0));
    scene->addItem(pix);

    s_no = new QGraphicsTextItem("");
    s_no->setZValue(pix->zValue()+1);
    s_no->setPos(QPointF(168,131));
    s_no->setFont(sfont2);
    QColor cred("red");
    s_no->setDefaultTextColor(cred);

    sname = new QGraphicsTextItem("");
    sname->setZValue(pix->zValue()+1);
    sname->setPos(QPointF(230,191));
    sname->setFont(sfont);

    fname = new QGraphicsTextItem("");
    fname->setZValue(pix->zValue()+1);
    fname->setPos(QPointF(115,216));
    fname->setFont(sfont);

    sdetail = new QGraphicsTextItem("");
    sdetail->setPos(QPointF(273,271));
    sdetail->setZValue(pix->zValue()+1);
    sdetail->setFont(sfont);

    periodfrom = new QGraphicsTextItem("");
    periodfrom->setZValue(pix->zValue()+1);
    periodfrom->setPos(QPointF(192,300));
    periodfrom->setFont(sfont);

    periodto = new QGraphicsTextItem("");
    periodto->setZValue(pix->zValue()+1);
    periodto->setPos(QPointF(294,300));
    periodto->setFont(sfont);

    date = new QGraphicsTextItem(dt);
    date->setZValue(pix->zValue()+1);
    date->setPos(QPointF(515,132));
    date->setFont(sfont);

    roll = new QGraphicsTextItem("");
    roll->setZValue(pix->zValue()+1);
    roll->setPos(QPointF(206,244));
    roll->setFont(sfont);

    gen = new QGraphicsTextItem("");
    gen->setZValue(pix->zValue()+1);
    gen->setPos(QPointF(505,191));
    gen->setFont(sfont);

    purpose = new QGraphicsTextItem("");
    purpose->setZValue(pix->zValue()+1);
    purpose->setPos(QPointF(365,339));
    purpose->setFont(sfont);

    purposetext = new QGraphicsTextItem("");
    purposetext->setZValue(pix->zValue()+1);
    purposetext->setPos(QPointF(30,339));
    purposetext->setFont(sfont);

    scene->addItem(s_no);
    scene->addItem(fname);
    scene->addItem(sname);
    scene->addItem(sdetail);
    scene->addItem(periodfrom);
    scene->addItem(periodto);
    scene->addItem(roll);
    scene->addItem(date);
    scene->addItem(gen);
    scene->addItem(purpose);
    scene->addItem(purposetext);
    ui.gview->setScene(scene);
}
Esempio n. 10
0
	int Augmentation(std::vector<int> &free_rows) {
		if(free_rows.size() < 1)
			return 1;
		for(unsigned int ind=0 ; ind<free_rows.size() ; ind++) {
			int free_row = free_rows[ind];
			double minimum_d;
			std::deque<int> ready_deque, scan_deque;
			std::vector<int> todo_list;
			ready_deque.clear(); scan_deque.clear(); todo_list.clear();
			Eigen::ArrayXi pred = Eigen::ArrayXi::Constant(n_, free_row);
			Eigen::ArrayXd d = Eigen::ArrayXd::Zero(n_);
			for(int col=1 ; col<=n_ ; col++) {
				todo_list.push_back(col);
				d(col-1) = cost_mat_(free_row-1, col-1) - v_(col-1);
			}
			while(1) {
				int done = 0;
				if(scan_deque.empty()) {
					minimum_d = inf_;
					std::vector<int> deposit;
					std::vector<int>::iterator todo_itr = todo_list.begin();
					while(todo_itr != todo_list.end()) {
						if(d((*todo_itr)-1) <= minimum_d) {
							if(d((*todo_itr)-1) < minimum_d) {
								minimum_d = d((*todo_itr)-1);
								for(unsigned int ind2=0 ; ind2<scan_deque.size() ; ind2++)
									deposit.push_back(scan_deque[ind2]);
								scan_deque.clear();
							}
							scan_deque.push_back((*todo_itr));
							todo_itr = todo_list.erase(todo_itr);
						}else{
							++todo_itr;
						}
					}
					for(unsigned int ind2=0 ; ind2<deposit.size() ; ind2++)
						todo_list.push_back(deposit[ind2]);
					deposit.clear();
					////
					for(unsigned int ind2=0 ; ind2<scan_deque.size() ; ind2++) {
						if(y_(scan_deque[ind2]-1) == 0) {
							Augment(free_row, scan_deque[ind2], ready_deque, minimum_d, d, pred);
							done = 1;
						}
						if(done) break;
					}
					if(done) break;
				}
				int scan_col = scan_deque.front();
				scan_deque.pop_front();
				int prev_row = y_(scan_col-1);
				ready_deque.push_back(scan_col);
				////
				std::vector<int>::iterator todo_itr = todo_list.begin();
				while(todo_itr != todo_list.end()) {
					int erase = 0;
					if(minimum_d + cred(prev_row, *todo_itr) < d((*todo_itr)-1)) {
						d((*todo_itr)-1) = minimum_d + cred(prev_row, *todo_itr);
						pred((*todo_itr)-1) = prev_row;
						if(d((*todo_itr)-1) == minimum_d) {
							if(y_((*todo_itr)-1) == 0) {
								Augment(free_row, (*todo_itr), ready_deque, minimum_d, d, pred);
								done = 1;
							} else {
								scan_deque.push_back(*todo_itr);
								todo_itr = todo_list.erase(todo_itr);
								erase = 1;
							}
							if(done) break;
						}
					}
					if(!erase)
						++todo_itr;
				}
				if(done) break;
			}
		}
		return 0;
	}
Esempio n. 11
0
 void ScanWiew::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *)
 {

     QColor cred(255,0,0);
     QColor cgreen(0,100,0);
      QColor cgreen2(0,150,0);
     QColor cblue(0,0,255);

     QPen pred(cred);
     QPen pgreen(cgreen);
     QPen pgreen2(cgreen2);
     QPen pblue(cblue);

     painter->setPen(pgreen);

     //QFont fcnew("Coruier new", 10, QFont::Normal);
     QFontMetrics fm(painter->font());

     int pixelsHeight = fm.height();
     int lineCnt = laserRangeInMeter/arcDistanceInMeter;

     for(int i = 1; i <= lineCnt; i++)
     {

         QRectF rectangle(-(i*arcDistanceInPixels), -(i*arcDistanceInPixels), i*2*arcDistanceInPixels,i*2*arcDistanceInPixels);
         int spanAngle = endAngle - startAngle+5;

         painter->drawArc(rectangle, ((int)startAngle+90-5)*16, (spanAngle+5)*16);

         int x = -::sin((startAngle-5)*TwoPi/360)*(i*arcDistanceInPixels);
         int y = -::cos((startAngle-5)*TwoPi/360)*(i*arcDistanceInPixels);


         char str[100];
         sprintf(str,"%d",i*(int)arcDistanceInMeter);
         int pixelsWide = fm.width(str);
         QPoint ptl(x-pixelsWide,y);
         QPoint pbr(x,y+pixelsHeight);
         QRect rt(ptl,pbr);

         painter->drawText(rt, Qt::AlignCenter, (QString)(str));

         x = -::sin((endAngle+5)*TwoPi/360)*(i*arcDistanceInPixels);
         y = -::cos((endAngle+5)*TwoPi/360)*(i*arcDistanceInPixels);


         QPoint ptl1(x,y);
         QPoint pbr1(x+pixelsWide,y+pixelsHeight);
         QRect rt1(ptl1,pbr1);
         painter->drawText(rt1, Qt::AlignCenter, (QString)(str));

     }


     lineCnt = (endAngle - startAngle)/angleDelta;
     double ang = startAngle;

     int distance = (laserRangeInMeter/arcDistanceInMeter)*arcDistanceInPixels;

     for(int i = 0; i <= lineCnt ; i++)
     {
         painter->setPen(pgreen);
         int x = -::sin(ang*TwoPi/360)*(distance+5);
         int y = -::cos(ang*TwoPi/360)*(distance+5);
         painter->drawLine(0,0,x,y);

         char str[100];
         sprintf(str,"%d",(int)ang);
         int pixelsWide = fm.width(str);


         x = -::sin(ang*TwoPi/360)*(distance+20);
         y = -::cos(ang*TwoPi/360)*(distance+20);

         QPoint ptl(x-pixelsWide/2,y - pixelsHeight/2);
         QPoint pbr(x+pixelsWide/2,y+pixelsHeight/2);
         QRect rt(ptl,pbr);
         painter->drawText(rt, Qt::AlignCenter, (QString)(str));

         ang += angleDelta;
     }

     double olcek =  arcDistanceInPixels/arcDistanceInMeter;
     //printf("olcek: %f\n",olcek);
     pgreen.setWidth(pgreen.width()+2);
     painter->setPen(pgreen2);
     for(int i = 0; i < pointCnt; i++)
     {
         painter->drawLine(0,0,-plist[i].y*olcek,-plist[i].x*olcek);
     }

      painter->setPen(pred);
     plinel_t *root = g_line_map.first;

     while(root != NULL)
     {
        if(root->line.length > 0.05 && root->point_cnt > 3 )//MIN_LENGTH_LINE_TO_SEND)
        {
           painter->drawLine(-root->line.sp.y*olcek,-root->line.sp.x*olcek,-root->line.ep.y*olcek,-root->line.ep.x*olcek);
        }
        root = root->next;
     }
 }
Esempio n. 12
0
std::istream* HTTPStreamFactory::open(const URI& uri)
{
	poco_assert (uri.getScheme() == "http");

	URI resolvedURI(uri);
	URI proxyUri;
	HTTPClientSession* pSession = 0;
	HTTPResponse res;
	bool retry = false;
	bool authorize = false;
	std::string username;
	std::string password;

	try
	{
		do
		{
			if (!pSession)
			{
				pSession = new HTTPClientSession(resolvedURI.getHost(), resolvedURI.getPort());
			
				if (proxyUri.empty())
					pSession->setProxy(_proxyHost, _proxyPort);
				else
					pSession->setProxy(proxyUri.getHost(), proxyUri.getPort());
				pSession->setProxyCredentials(_proxyUsername, _proxyPassword);
			}
						
			std::string path = resolvedURI.getPathAndQuery();
			if (path.empty()) path = "/";
			HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
			
			if (authorize)
			{
				HTTPCredentials::extractCredentials(uri, username, password);
				HTTPCredentials cred(username, password);
				cred.authenticate(req, res);
			}
			
			pSession->sendRequest(req);
			std::istream& rs = pSession->receiveResponse(res);
			bool moved = (res.getStatus() == HTTPResponse::HTTP_MOVED_PERMANENTLY || 
						  res.getStatus() == HTTPResponse::HTTP_FOUND || 
						  res.getStatus() == HTTPResponse::HTTP_SEE_OTHER ||
						  res.getStatus() == HTTPResponse::HTTP_TEMPORARY_REDIRECT);
			if (moved)
			{
				resolvedURI.resolve(res.get("Location"));
				if (!username.empty())
				{
					resolvedURI.setUserInfo(username + ":" + password);
				}
				throw URIRedirection(resolvedURI.toString());
			}
			else if (res.getStatus() == HTTPResponse::HTTP_OK)
			{
				return new HTTPResponseStream(rs, pSession);
			}
			else if (res.getStatus() == HTTPResponse::HTTP_USEPROXY && !retry)
			{
				// The requested resource MUST be accessed through the proxy 
				// given by the Location field. The Location field gives the 
				// URI of the proxy. The recipient is expected to repeat this 
				// single request via the proxy. 305 responses MUST only be generated by origin servers.
				// only use for one single request!
				proxyUri.resolve(res.get("Location"));
				delete pSession; pSession = 0;
				retry = true; // only allow useproxy once
			}
			else if (res.getStatus() == HTTPResponse::HTTP_UNAUTHORIZED && !authorize)
			{
				authorize = true;
				retry = true;
				Poco::NullOutputStream null;
				Poco::StreamCopier::copyStream(rs, null);
			}
			else throw HTTPException(res.getReason(), uri.toString());
		}
		while (retry);
		throw HTTPException("Too many redirects", uri.toString());
	}
	catch (...)
	{
		delete pSession;
		throw;
	}
}
Esempio n. 13
0
gss_cred_id_t read_globus_credentials(const std::string& filename) {
  Arc::Credential cred(filename, "", "", "", "", true);
  X509* cert = cred.GetCert();
  STACK_OF(X509)* cchain = cred.GetCertChain();
  EVP_PKEY* key = cred.GetPrivKey();
  globus_gsi_cred_handle_t chandle;
  globus_gsi_cred_handle_init(&chandle, NULL);
  if(cert) globus_gsi_cred_set_cert(chandle, cert);
  if(key) globus_gsi_cred_set_key(chandle, key);
  if(cchain) globus_gsi_cred_set_cert_chain(chandle, cchain);

  gss_cred_id_desc* ccred = (gss_cred_id_desc*)::malloc(sizeof(gss_cred_id_desc));
  if(ccred) {
    ::memset(ccred,0,sizeof(gss_cred_id_desc));
    ccred->cred_handle = chandle; chandle = NULL;
    // cred_usage
    // ssl_context
    X509* identity_cert = NULL;
    if(cert) {
      globus_gsi_cert_utils_cert_type_t ctype = GLOBUS_GSI_CERT_UTILS_TYPE_DEFAULT;
      globus_gsi_cert_utils_get_cert_type(cert,&ctype);
      if(ctype == GLOBUS_GSI_CERT_UTILS_TYPE_EEC) {
        identity_cert = cert;
      };
    };
    if(!identity_cert && cchain) {
      // For compatibility with older globus not using
      //globus_gsi_cert_utils_get_identity_cert(cchain,&identity_cert);
      for(int n = 0; n < sk_X509_num(cchain); ++n) {
        X509* tmp_cert = sk_X509_value(cchain, n);
        if(tmp_cert) {
          globus_gsi_cert_utils_cert_type_t ctype = GLOBUS_GSI_CERT_UTILS_TYPE_DEFAULT;
          globus_gsi_cert_utils_get_cert_type(tmp_cert,&ctype);
          if(ctype == GLOBUS_GSI_CERT_UTILS_TYPE_EEC) {
            identity_cert = tmp_cert;
            break;
          };
        };
      };
    };
    gss_buffer_desc peer_buffer;
    peer_buffer.value = identity_cert;
    peer_buffer.length = identity_cert?sizeof(X509):0;
    OM_uint32 majstat, minstat;
    majstat = gss_import_name(&minstat, &peer_buffer,
                              identity_cert?GLOBUS_GSS_C_NT_X509:GSS_C_NT_ANONYMOUS,
                              &ccred->globusid);
    if (GSS_ERROR(majstat)) {
      logger.msg(Arc::ERROR, "Failed to convert GSI credential to "
         "GSS credential (major: %d, minor: %d)", majstat, minstat);
      majstat = gss_release_cred(&minstat, &ccred);
    };
  } else {
    ccred = GSS_C_NO_CREDENTIAL;
  };
  if(cert) X509_free(cert);
  if(key) EVP_PKEY_free(key);
  if(cchain) sk_X509_pop_free(cchain, X509_free);
  if(chandle) globus_gsi_cred_handle_destroy(chandle);
  return ccred;
}
/*11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
*******************************************************************************************************************************
***************************************************** menu_homogene ***********************************************************/
void menuu1(PileGe pg,Pile* p,int choix){
    if(choix!=1 && choix!=2){
    printf("\t**********************************************************************\n");
	printf("\t*************************** Pile Generique Homogene ******************\n");
	printf("\t**********************************************************************\n");
	printf("\t*********************** 1. Pile de Ints ******************************\n");
	printf("\t*********************** 2. Pile de Livres ****************************\n");
	printf("\t*********************** 0. Retour au menu precedent ******************\n");
    printf("\tChoix =");
	scanf("%d",&choix);
	if(choix==1)
        pg=pile_videG(INTS);
    else if(choix==2){
        pg=pile_videG(LIVRE);

    }else{
        system("cls");
        menuu(pg,p);
    }
        }
	char* t;
	if(choix==1){

        t="Int";}
    else{

        t="Livre";
    }

/******************************************************************************************************************************/

    printf("\t**********************************************************************\n");
	printf("\t********************** Pile de %s                  ****************\n",t);
	printf("\t**********************************************************************\n");
	printf("\t*********************** 1. Tester si la pile est vide     ************\n");
	printf("\t*********************** 2. Empiler un %s               ************\n",t);
	printf("\t*********************** 3. Depiler                         ***********\n");
	printf("\t*********************** 4. Visualiser le sommet de la pile ***********\n");
	printf("\t*********************** 5. Retour                              *******\n");

	int i=0;
	printf("\tChoix=");
	scanf("%d",&i);

	switch (i){
		case 1:{
		    system("cls");
			if(is_emptyG(pg))
                printf("\tLa pile est vide\n");
            else{
                printf("\tLa pile n'est pas vide\n");
            }
            menuu1(pg,p,choix);
			break;
		}
		case 2:{
		    system("cls");
		    int in;
			if(choix==1){
                printf("\tEnter l'entier a empiler :\n \tn=");
                scanf("%d",&in);
                pg=pushG(pg,&in);
            }
            else{
                char ID[20];
                printf("\tL'ID : ");
                scanf("%s",ID);
                char Titre[20];
                printf("\tLe titre : ");
                scanf("%s",Titre);
                char Auteur[20];
                printf("\tL'auteur : ");
                scanf("%s",Auteur);
                int np;
                printf("\tLe numero de pages dans ce livre : ");
                scanf("%d",&np);
                int j,m,y;
                printf("\tLa Date de publication en format jj/mm/yy : ");
                char a,b;
                scanf("%d %c %d %c %d",&j,&a,&m,&b,&y);
                Date dd=cred(j,m,y);
                Livre liv=crel(ID,Titre,Auteur,np,dd);
                pg=pushG(pg,&liv);
            }
            menuu1(pg,p,choix);
			break;
		}
     	case 3:{
		    system("cls");
		    pg=pullG(pg);
			menuu1(pg,p,choix);
			break;
		}
		case 4:{
		    system("cls");
		    printf("\tLe sommet de la pile est :\n");
		    headG(pg);
		    printf("\n");
			menuu1(pg,p,choix);
			break;
		}
		case 5:{
		    system("cls");
			menuu(pg,p);
			break;
		}

		default :{
		    system("cls");
			printf("\tVotre choix est invalide !!\n");
			menuu1(pg,p,choix);
		}
	}
}
/*******************************************************************************************************************************
***************************************************** menu_heterogene ***********************************************************/
void menuu2(PileGe pg,Pile* p){

    printf("\t***********************************************************************\n");
	printf("\t*************************** Pile Generique Heterogene *****************\n");
	printf("\t***********************************************************************\n");
	printf("\t*********************** 1. Tester si la pile est vide       ***********\n");
	printf("\t*********************** 2. Empiler un Element               ***********\n");
	printf("\t*********************** 3. Depiler                          ***********\n");
	printf("\t*********************** 4. Visualiser le sommet de la pile  ***********\n");
	printf("\t*********************** 5. Retour au menu precedent         ***********\n");

	int i=0;
	printf("\tn=");
	scanf("%d",&i);
	switch (i){
		case 1:{
		    system("cls");
			if(est_vide(p))
                printf("\tLa pile est vide\n");
            else{
                printf("\tLa pile n'est pas vide\n");
            }
            menuu2(pg,p);
			break;
		}
		case 2:{
		    system("cls");
    int choix;
	printf("\t1. Empiler un Int\n");
	printf("\t2. Empiler un Livre\n");
	scanf("%d",&choix);



			if(choix==1){
                    int in;
                printf("\tEnter le int a empiler:\n n=");
                scanf("%d",&in);
                empiler(p,in,entier);

                }
            else{
                char ID[20];
			printf("\tL'ID : ");
			scanf("%s",ID);
			char Titre[20];
			printf("\tLe titre : ");
			scanf("%s",Titre);
			char Auteur[20];
			printf("\tL'auteur : ");
			scanf("%s",Auteur);
			int np;
			printf("\tLe numero de pages dan ce livre : ");
			scanf("%d",&np);
			int j,m,y;
			printf("\tLa Date de publication en format jj/mm/yy : ");
			char a,b;
			scanf("%d %c %d %c %d",&j,&a,&m,&b,&y);
			Date dd=cred(j,m,y);
			Livre liv=crel(ID,Titre,Auteur,np,dd);
			 empiler(p,nv_livre(ID,Auteur,Titre,np,j,m,y),livre);
            }
            menuu2(pg,p);
			break;
		}
     	case 3:{
		    system("cls");
		    depiler(p);
			menuu2(pg,p);
			break;
		}
		case 4:{
		    system("cls");
		    printf("le sommet de la pile est :");
		     Element *E;
             E=p->tete;
             if(E!=NULL){
            Afficher_element(E->donnee);

        }
		    printf("\n");
			menuu2(pg,p);
			break;
		}
		case 5:{
		    system("cls");
			menuu(pg,p);
			break;
		}

		default :{
		    system("cls");
			printf("Votre choix est invalide !!\n");
			menuu2(pg,p);
		}
	}

}
	uint32 count() const	{ return cred() ? cred()->samples().length() : 0; }
	const TypedList &sample(uint32 n) const
	{ assert(n < count()); return cred()->samples()[n]; }
Esempio n. 18
0
void credgen_tests::test_credgen_irma_testvec()
{
	mpz_class n("0x88CC7BD5EAA39006A63D1DBA18BDAF00130725597A0A46F0BACCEF163952833BCBDD4070281CC042B4255488D0E260B4D48A31D94BCA67C854737D37890C7B21184A053CD579176681093AB0EF0B8DB94AFD1812A78E1E62AE942651BB909E6F5E5A2CEF6004946CCA3F66EC21CB9AC01FF9D3E88F19AC27FC77B1903F141049");
	mpz_class Z("0x3F7BAA7B26D110054A2F427939E61AC4E844139CEEBEA24E5C6FB417FFEB8F38272FBFEEC203DB43A2A498C49B7746B809461B3D1F514308EEB31F163C5B6FD5E41FFF1EB2C5987A79496161A56E595BC9271AAA65D2F6B72F561A78DD6115F5B706D92D276B95B1C90C49981FE79C23A19A2105032F9F621848BC57352AB2AC");
	mpz_class S("0x617DB25740673217DF74BDDC8D8AC1345B54B9AEA903451EC2C6EFBE994301F9CABB254D14E4A9FD2CD3FCC2C0EFC87803F0959C9550B2D2A2EE869BCD6C5DF7B9E1E24C18E0D2809812B056CE420A75494F9C09C3405B4550FD97D57B4930F75CD9C9CE0A820733CB7E6FC1EEAF299C3844C1C9077AC705B774D7A20E77BA30");
	std::vector<mpz_class> R;
	
	R.push_back(mpz_class("0x6B4D9D7D654E4B1285D4689E12D635D4AF85167460A3B47DB9E7B80A4D476DBEEC0B8960A4ACAECF25E18477B953F028BD71C6628DD2F047D9C0A6EE8F2BC7A8B34821C14B269DBD8A95DCCD5620B60F64B132E09643CFCE900A3045331207F794D4F7B4B0513486CB04F76D62D8B14B5F031A8AD9FFF3FAB8A68E74593C5D8B"));
	R.push_back(mpz_class("0x177CB93935BB62C52557A8DD43075AA6DCDD02E2A004C56A81153595849A476C515A1FAE9E596C22BE960D3E963ECFAC68F638EBF89642798CCAE946F2F179D30ABE0EDA9A44E15E9CD24B522F6134B06AC09F72F04614D42FDBDB36B09F60F7F8B1A570789D861B7DBD40427254F0336D0923E1876527525A09CDAB261EA7EE"));
	R.push_back(mpz_class("0x12ED9D5D9C9960BACE45B7471ED93572EA0B82C611120127701E4EF22A591CDC173136A468926103736A56713FEF3111FDE19E67CE632AB140A6FF6E09245AC3D6E022CD44A7CC36BCBE6B2189960D3D47513AB2610F27D272924A84154646027B73893D3EE8554767318942A8403F0CD2A41264814388BE4DF345E479EF52A8"));
	R.push_back(mpz_class("0x7AF1083437CDAC568FF1727D9C8AC4768A15912B03A8814839CF053C85696DF3A5681558F06BAD593F8A09C4B9C3805464935E0372CBD235B18686B540963EB9310F9907077E36EED0251D2CF1D2DDD6836CF793ED23D266080BF43C31CF3D304E2055EF44D454F477354664E1025B3F134ACE59272F07D0FD4995BDAACCDC0B"));
	R.push_back(mpz_class("0x614BF5243C26D62E8C7C9B0FAE9C57F44B05714894C3DCF583D9797C423C1635F2E4F1697E92771EB98CF36999448CEFC20CB6E10931DED3927DB0DFF56E18BD3A6096F2FF1BFF1A703F3CCE6F37D589B5626354DF0DB277EF73DA8A2C7347689B79130559FB94B6260C13D8DC7D264BA26953B906488B87CDC9DFD0BC69C551"));
	R.push_back(mpz_class("0x5CAE46A432BE9DB72F3B106E2104B68F361A9B3E7B06BBE3E52E60E69832618B941C952AA2C6EEFFC222311EBBAB922F7020D609D1435A8F3F941F4373E408BE5FEBAF471D05C1B91030789F7FEA450F61D6CB9A4DD8642253327E7EBF49C1600C2A075EC9B9DEC196DDBDC373C29D1AF5CEAD34FA6993B8CDD739D04EA0D253"));
	R.push_back(mpz_class("0x52E49FE8B12BFE9F12300EF5FBDE1800D4611A587E9F4763C11E3476BBA671BFD2E868436C9E8066F96958C897DD6D291567C0C490329793F35E925B77B304249EA6B30241F5D014E1C533EAC27AA9D9FCA7049D3A8D89058969FC2CD4DC63DF38740701D5E2B7299C49EC6F190DA19F4F6BC3834EC1AE145AF51AFEBA027EAA"));
	R.push_back(mpz_class("0x05AA7EE2AD981BEE4E3D4DF8F86414797A8A38706C84C9376D324070C908724BB89B224CB5ADE8CDDB0F65EBE9965F5C710C59704C88607E3C527D57A548E24904F4991383E5028535AE21D11D5BF87C3C5178E638DDF16E666EA31F286D6D1B3251E0B1470E621BEE94CDFA1D2E47A86FD2F900D5DDCB42080DAB583CBEEEDF"));
	R.push_back(mpz_class("0x73D3AB9008DC2BD65161A0D7BFC6C29669C975B54A1339D8385BC7D5DEC88C6D4BD482BFBC7A7DE44B016646B378B6A85FBC1219D351FE475DC178F90DF4961CA980EB4F157B764EC3ECF19604FEDE0551AA42FB12B7F19667AC9F2C46D1185E66072EA709CC0D9689CE721A47D54C028D7B0B01AEEC1C4C9A03979BE9080C21"));
	R.push_back(mpz_class("0x33F10AB2D18B94D870C684B5436B38AC419C08FB065A2C608C4E2E2060FE436945A15F8D80F373B35C3230654A92F99B1A1C8D5BB10B83646A112506022AF7D4D09F7403EC5AECDB077DA945FE0BE661BAFEDDDDC5E43A4C5D1A0B28AE2AA838C6C8A7AE3DF150DBD0A207891F1D6C4001B88D1D91CF380EE15E4E632F33BD02"));
	
	silvia_pub_key pubkey(n, S, Z, R);
	
	silvia_credential_generator cred(&pubkey);
	
	silvia_integer_attribute m1(1313);
	silvia_integer_attribute m2(1314);
	silvia_integer_attribute m3(1315);
	silvia_integer_attribute m4(1316);
	
	std::vector<silvia_attribute*> attributes;
	attributes.push_back(&m1);
	attributes.push_back(&m2);
	attributes.push_back(&m3);
	attributes.push_back(&m4);
	
	cred.set_attributes(attributes);
	
	silvia_integer_attribute s(mpz_class("0xB1173E9CFA91149B60B6A3A5822B49FAF79A6EED971469FCABEA79BC82AF36E0"));
	cred.set_secret(s);
	
	// Test computing the commitment
	mpz_class U;
	mpz_class v_prime;
	mpz_class v_prime_test("0xAE472CE185E9484385B2B9D6CA64FD44AC3E45688A780389B73B4F0C266F110291798C303B0C7C28EDFEBCEA0B783F138AB00C873B820B8F77D659127286429A184C28E122743E31731487D6D049C981D09DEC7DB0909223C765E5027C3A4D7B64F61FACDA5FD9D20BDEA131EF2A16ED508E5393C632F28ED603E724ACE9E922410E2D6F85BA4B25DC8C");
	
	cred.compute_commitment(U, v_prime, &v_prime_test);
	
	CPPUNIT_ASSERT(U == mpz_class("0x303150D3557EC3496A6720FC23D5B77A4B6E396D86C130A3BD9B886EE86307D3F12BCE8AEC0D8C46AD20628C4F0C58AFD5E6E699BFFC398712FC202F1EA825FD42AA4D461E5C7C5D7294588331BDE3810E31609A6B963698F8A2F518AA6B58E0F8A7EFE52DB5DCC864AAECF4C817A33342F53BBADDE6EFE247E14CAB2010BEE4"));
	
	// Test proof of commitment
	mpz_class c;
	mpz_class v_prime_hat;
	mpz_class s_hat;
	
	mpz_class s_tilde_test("0x018CB1BFAAD3402714E796B4E2F7DC7246950A074D0A5F782E25005611FC6374FDC395DE21023512990742ACC70FBA8AED6FB68F17A4D84C7A27486E56099C");
	mpz_class v_prime_tilde_test("0xF87EFB6925659CA77DC2247069D84FC7CAA60318C4222A9FA16E303B92234367909AB4E082FCDF66692D98FE019E86DF0347FAD1AF09AE55F7E6C0F736586CBD9B14BC23F556F29DCA1CA79018C8AC611E21202A3FDE1A9FB50C0CD9044271ECA4A0C3595006085FC2891F72C88C63CF79E843F21C9CA426A808BC1A43297112C7C34A125967B85BEB4249EFCC2C16455CF796A0851D50EEEB115AA08A58C2DF86D1F08C40E5C47D");
	mpz_class n1_test("0x80FC58C623C80FC7092D");
	mpz_class context("0xBA45FCF32A16B18C344865A288F4D421A3C5FE03");
	
	cred.prove_commitment(n1_test, context, c, v_prime_hat, s_hat, &s_tilde_test, &v_prime_tilde_test);
	
	CPPUNIT_ASSERT(c == mpz_class("0x7838BDCB7F99A8AC732BC867F800E16A61361D38"));
	CPPUNIT_ASSERT(v_prime_hat == mpz_class("0xF87EFB6925659CA77DC2764867A8ED5370E1B2C5A3D073D1B40AA06A0529D309BF552A2ACE20E9167B1EB661C4FA0CB5398068D58A66AEC0D980C34E2B8CAA260F6720ADF052C4B5AB07E490D84BF4E42A7748EC4148502E1A744CCB42BD2D0C6F20B600E15121F57ED991AC8903A4BF2F2D393BEC08984648FB0B65FD9D3195991E8E1E734C2C45D24BBD7220956780FF48B22E40329E8C44F84C9790FA557BE9A6DC558CB1DF1D"));
	CPPUNIT_ASSERT(s_hat == mpz_class("0x018CB1BFAAD3402714E797080D1D96A8FEC58A0462672573A44ED3993AFA77505089E7F691A7ABE0939129DC3E9D2517361C7135AD7760AE9EB0D351216A9C"));
	
	// Test signature proof validation
	mpz_class n2_test("0x7BAF54ECE6CADE702CB8");
	
	cred.get_prover_nonce(&n2_test);
	
	mpz_class A("0x37FB456B3D4D38F890F5DECDBE8147DD476A8F951E325EB3E860ABD2CCD4F52A1EF46594ED2D450869328DFFF6ACBD049BB8DD7AE4E256EB501B79BC17E1D68AB224D9CC310EB73CC218C43E860346942D690BBCEE7A3ED392D3933BB8CE6D4539A4D08475738A84B0FFB7D1A0CF25644E6EABC97A52C62BBC507E6885D16373");
	mpz_class e("0x8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006D093A6A327D0392ED2787DA24BB7D");
	mpz_class c_1("0xBE19129671FE5140C1E267A337AB4083C93EBC18");
	mpz_class e_hat("0x0137B079E0B05ADB0F1075005BA70D61EBEEE7A7DCC5DC685354F335FD7B53A6844B3E70E2CFCD38B5DDDD4470E6F520A20C496D6F587D3B8F690E8AA9090217F630481A05FDFC44DFF364574735BAFE4F29874812D4BD73EBDB10B631DA2C91D27059B9D52B679E86C8B6732C9A7020DD6E8B686D179C9767C50F1775215F0A");
	
	CPPUNIT_ASSERT(cred.verify_signature(context, A, e, c_1, e_hat) == true);
	
	// Test credential verification
	mpz_class v_prime_prime("0x0B2067BB63FEF96D093A81CB7BD270188E5F47AEEA74A350C3848114E353E0E2654205BAD43B632DDDC23CA357780544A63AA4ACCE35C6D9123C34CD31ABD153FF6FC59E7898CA6CEFE4A748E26384148C695EFC910E12AFFB16F0299A1F9A1B20BF84FB0E886BC32B135093600B674DCDD82A30595E64063358E18BD012752D21DC1A5657A6F8E466924D596031A8237E5A98F9636AAEFF55FE86A9AF973523611583B5B64E7713B84983759ED517382C9922A04B58BA086D6D121B277B06356041C8F2244D04D2BC");
	
	cred.compute_credential(A, e, v_prime_prime);
	
	CPPUNIT_ASSERT(cred.verify_credential() == true);
	
	silvia_credential* new_cred = cred.get_credential();
	
	mpz_class v_test("0x0B2067BB63FEF96D093A81CB7BD270188E5F47AEEA74A350C3848114E353E0E2654205BAD43B632DDDC23CA357780544A63AA4ACCE35C6D9123C34CD31ABD202469CA72461E10DF2A29E7E134760C8C0CAAEC78709119C673665FC5009309CAC9A4BB5361B0494B129D03A9ED84A7AD87DE4B16BDB69F37E09B1F3FE56550F456E04FB78CBE52A577B1A2429A9FB29F41C4716A9F3FCD2C6BBE38925E9E4B088573530901628491F96EAB564C8EC0488BAECB6667E4B48DE715436C8116428766E6F3877DE982AAF48");
	
	CPPUNIT_ASSERT(new_cred->get_A() == A);
	CPPUNIT_ASSERT(new_cred->get_e() == e);
	CPPUNIT_ASSERT(new_cred->get_v() == v_test);
	CPPUNIT_ASSERT(new_cred->get_secret() == s);
	CPPUNIT_ASSERT(new_cred->num_attributes() == 4);
	CPPUNIT_ASSERT(new_cred->get_attribute(0)->rep() == m1.rep());
	CPPUNIT_ASSERT(new_cred->get_attribute(1)->rep() == m2.rep());
	CPPUNIT_ASSERT(new_cred->get_attribute(2)->rep() == m3.rep());
	CPPUNIT_ASSERT(new_cred->get_attribute(3)->rep() == m4.rep());

	delete new_cred;
}