Eye-fi card need key that I believe is a MD5 hash - hash

I am stuck with some Eyefi cards, because manufacturer decide to disable it by stopping registration server.
I need an Uploadkey for each card in order to use them. I can get the MAC address of the card, and I believe the hash are generated using these address (may be only right side of the address) plus a salt. Here are some correct uploadkey and Mac addesses, can anybody help me to find out how can we generate the uploadkey using the MAC address.
00-18-56-26-fb-9a f7714f1c6375e329c49704cc2b228610
00-18-56-27-04-91 3599db80740e842be3e51b1a68c50800
00-18-56-60-35-32 c6172ad74fd9f3d089114190e7415bf6
00-18-56-23-89-08 24976afddd2bd6c9ba84024e122313f1
00-18-56-65-48-89 b884d91ed551e9debcaa30cbbed454cf
00-18-56-41-cd-45 7d0c4807cdfb93759b38e468fb6f7796
00-18-56-2b-90-f9 7c207b004d7776b266d7896a42323a81
00-18-56-65-44-28 d721236649997f7d326c3b00fb3c6f2f
00-18-56-65-44-3b 48c8cb73afdf13ada7f636ac618ed1c6
00-18-56-66-a8-71 7989ad884bfd0456f65b5c56655e56a2
00-18-56-66-a8-ac ba01f5c3a49c5309c7655d3bf8b9dc22
00-18-56-66-ac-ca 8ee95d7e6f703fd1bc850e057f471973
00-18-56-66-ac-ac 816c40bdb86a88a79c72a88cc95ed251
00-18-56-66-a0-f9 1cfa78d59161a0ef2068a33cf29a83a9
00-18-56-65-48-c8 f26d16bb221bfb2953cdfc65cc0491a3
00-18-56-66-a1-ee 4e1803543ac47884ebb1437a966f89e2
00-18-56-66-a2-22 386b8a3c6a37828df4b6fccbe8ace943
00-18-56-66-a8-b2 0eae0b55245f2698f28ac496c3c3dbaa
00-18-56-66-ac-9e f36a098fe506be172fb6b067ef00352d
00-18-56-65-51-e7 29c555c9c4b413ea539f51f3a82f263e
00-18-56-48-9a-cd c448958ec576198fdb478febca71c53e
00-18-56-65-48-ef b07cfd70d1890749ff877e44644e5971
00-18-56-26-fe-24 9f73c96e263b14a608802317004c6b98
00-18-56-49-90-6a 364624a58431a5bd65fec56e10003559
00-18-56-60-86-e0 b831e3985a08d4ae1b17548e35036843
00-18-56-64-be-d1 9d5de14ff7d31ecc62b17e0adc3d58fa
00-18-56-64-b7-ac 9fa650cff40dfde43fbf5cac83d8cd8b
00-18-56-66-ab-01 b7f6f3d1280a0e9fe4ecb839a1c5d452
00-18-56-64-b8-43 69e5395dc84e529f50dbb61fbea19868
00-18-56-67-89-c1 f78b834bf125bd1011eea973737655d6
00-18-56-67-89-b2 636a94f10b111f3ecb2d86e483d3d188
00-18-56-67-88-f1 cffa4cf562dffae5bff6033bb431b2f7
00-18-56-67-89-8b 325878ed10fba08597b303913d0ad452
00-18-56-67-89-95 212a84620afa9468c0ad738256c70087
00-18-56-67-8b-94 a43af4eadb8dd895ec9218459edb2ced
00-18-56-67-89-2e e58890a80900371d1b354492885ddefb
00-18-56-67-89-70 b21c36f15331ec798fc91be09df99fe7
00-18-56-67-89-b8 fbf58645bf029b265732df898b7fa5a6
00-18-56-67-89-bd 069a55499764fdae6ff0594938e8e67b
00-18-56-67-89-3f 5923768b6296380369737e26e41f8a56
00-18-56-67-89-b5 c8e06cca653a899c58b936c5b67c4f6a
00-18-56-67-89-52 aac3ab4f10bbb2532e01f58cabce2099
00-18-56-67-89-20 62c6f2d4366fca2b0bbec0d89f2609c1
00-18-56-67-89-5b 78480c27f40b440b261e6539b9722ac0
00-18-56-67-8c-18 393f524169417b63f3d2bd78a4ffe1a8
00-18-56-27-04-69 5310953393797ce8c51939cd73916ebb
00-18-56-2b-90-f9 7c207b004d7776b266d7896a42323a81
00-18-56-2a-8e-c9 8413138729754199101c695391a22129
00-18-56-41-5f-1d 2d1c710c6c7b7dfd4d4ed151d9b25d60
00-18-56-67-89-33 d4258a40554dbd14c206e581ed18af5c
00-18-56-66-aa-90 ce5feb6b1721d1d561daa470fcf516cd
00-18-56-26-97-49 0a7f3af18d21a39c9a40d1afc9685172
00-18-56-2b-fa-41 374583671b464330650ca006882b6320
00-18-56-67-89-95 212a84620afa9468c0ad738256c70087
00-18-56-2c-14-29 7c0ca21f1e0cf05a21185deecbd8a1ba
There are many of us needed this key in order to use the card we paid for...
Referencnce https://www.os3.nl/_media/2013-2014/courses/ot/connor_stavros.pdf

Related

Itop export csv of functional CIs with wget / link

I want to export all the Functional CIs from a Specific Person. In the web-interface I can just click the wrench-icon and click export to csv, but when I try to do this with a link, it gets a bit more complicated. basically I'm trying to download this View:
or in text:
"FunctionalCI->Typ","FunctionalCI->Name","ID (Primärer Schlüssel)","Voller Name (Friendly Name)","Kontakt","Kontakt->Name","Kontakt->Voller Name (Friendly Name)","Kontakt->Typ","Kontakt->Obsolet","Kontakt->Organisation","Kontakt->Organisation","Kontakt->Email"
"Peripheriegerät","USBKI08018",3747,"3090 795",795,"Sample","Ex Sample","Person",Nein,6,"oragnisation","ex.sample#email.com"
"PC","FUJIQ58003",3395,"3837 795",795,"Sample","Ex Sample","Person",Nein,6,"oragnisation","ex.sample#email.com"
"Peripheriegerät","M056-1907",3432,"3898 795",795,"Sample","Ex Sample","Person",Nein,6,"oragnisation","ex.sample#email.com"
"Peripheriegerät","YUBIKEY013",3632,"3990 795",795,"Sample","Ex Sample","Person",Nein,6,"oragnisation","ex.sample#email.com"
"Peripheriegerät","MSDOCK102",4900,"4555 795",795,"Sample","Ex Sample","Person",Nein,6,"oragnisation","ex.sample#email.com"
"PC","MSSURL348",4895,"4663 795",795,"Sample","Ex Sample","Person",Nein,6,"oragnisation","ex.sample#email.com"
"Peripheriegerät","HEADSET431",6072,"5764 795",795,"Sample","Ex Sample","Person",Nein,6,"oragnisation","ex.sample#email.com"
I have tried multiple OQL's, but I can't get the user to link with its CIs. This is what I have tried:
https://itop.tirvers.at/itop/webservices/export-v2.php?expression=SELECT Person WHERE Person.friendlyname LIKE 'Ex Sample%'&fields=friendlyname, name, status, id&format=csv
This link actually works, but it only gives me more information about the person, which is not what I need. The next thing I tried was:
https://itop.tirvers.at/itop/webservices/export-v2.php?expression=SELECT FunctionalCI WHERE FunctionalCI.name LIKE 'FUJIQ58003%'&fields=id&format=csv
which also works, but, again, only yields more information about the FunctionalCI, which is not what I need.
With a bit of tinkering I got all the classes of the Server:
AsyncTask, AsyncSendEmail, DBProperty, CMDBChange, CMDBChangeOp, CMDBChangeOpCreate,
CMDBChangeOpDelete, CMDBChangeOpSetAttribute, CMDBChangeOpSetAttributeScalar,
CMDBChangeOpSetAttributeTagSet, CMDBChangeOpSetAttributeURL, CMDBChangeOpSetAttributeBlob,
CMDBChangeOpSetAttributeOneWayPassword, CMDBChangeOpSetAttributeEncrypted,
CMDBChangeOpSetAttributeText, CMDBChangeOpSetAttributeLongText, CMDBChangeOpSetAttributeHTML,
CMDBChangeOpSetAttributeCaseLog, CMDBChangeOpPlugin, CMDBChangeOpSetAttributeLinks,
CMDBChangeOpSetAttributeLinksAddRemove, CMDBChangeOpSetAttributeLinksTune,
CMDBChangeOpSetAttributeCustomFields, AuditCategory, AuditRule, Query, QueryOQL,
ModuleInstallation, ExtensionInstallation,
UserDashboard, Shortcut, ShortcutOQL, appUserPreferences, User, UserInternal, Event,
EventNotification, EventNotificationEmail, EventIssue, EventWebService, EventRestService,
EventLoginUsage,
EventOnObject, Action, ActionNotification, ActionEmail, Trigger, TriggerOnObject,
TriggerOnPortalUpdate, TriggerOnStateChange, TriggerOnStateEnter, TriggerOnStateLeave,
TriggerOnObjectCreate,
TriggerOnObjectDelete, TriggerOnObjectUpdate, lnkTriggerAction, TriggerOnThresholdReached,
BulkExportResult, iTopOwnershipToken, TagSetFieldData, SynchroDataSource, SynchroAttribute,
SynchroAttExtKey,
SynchroAttLinkSet, SynchroLog, SynchroReplica, BackgroundTask, InlineImage, KeyValueStore,
UserExternal, UserLDAP, UserLocal, EmailReplica, TriggerOnMailUpdate, MailInboxBase,
Attachment,
CMDBChangeOpAttachmentAdded, CMDBChangeOpAttachmentRemoved, Organization, Location, Contact,
Person, Team, Document, DocumentFile, DocumentNote, DocumentWeb, FunctionalCI, PhysicalDevice,
ConnectableCI, DatacenterDevice, NetworkDevice, Server, ApplicationSolution, BusinessProcess,
SoftwareInstance, Middleware, DBServer, WebServer, PCSoftware, OtherSoftware,
MiddlewareInstance,
DatabaseSchema, WebApplication, Software, Patch, OSPatch, SoftwarePatch, Licence, OSLicence,
SoftwareLicence, lnkDocumentToLicence, Typology, OSVersion, OSFamily, DocumentType,
ContactType,
Brand, Model, NetworkDeviceType, IOSVersion, lnkDocumentToPatch,
lnkSoftwareInstanceToSoftwarePatch, lnkFunctionalCIToOSPatch, lnkDocumentToSoftware,
lnkContactToFunctionalCI,
lnkDocumentToFunctionalCI, Subnet, VLAN, lnkSubnetToVLAN, NetworkInterface, IPInterface,
PhysicalInterface, lnkPhysicalInterfaceToVLAN, lnkConnectableCIToNetworkDevice,
lnkApplicationSolutionToFunctionalCI, lnkApplicationSolutionToBusinessProcess, l
InkPersonToTeam, Group, lnkGroupToCI, Rack, Enclosure, PowerConnection, PowerSource, PDU, PC,
Printer,
TelephonyCI, Phone, MobilePhone, IPPhone, Tablet, Peripheral, MailInboxStandard,
StorageSystem, SANSwitch, TapeLibrary, NAS, FiberChannelInterface, Tape, NASFileSystem,
LogicalVolume,
lnkServerToVolume, lnkSanToDatacenterDevice, Ticket, lnkContactToTicket,
lnkFunctionalCIToTicket, WorkOrder, VirtualDevice, VirtualHost, Hypervisor, Farm,
VirtualMachine, LogicalInterface,
AbstractResource, ResourceAdminMenu, ResourceRunQueriesMenu, ResourceSystemMenu,
lnkVirtualDeviceToVolume, Change, RoutineChange, ApprovedChange, NormalChange,
EmergencyChange, Incident,
KnownError, lnkErrorToFunctionalCI, lnkDocumentToError, FAQ, TagSetFieldDataFor_FAQ__domains,
FAQCategory, Problem, UserRequest, ContractType, Contract, CustomerContract, ProviderContract,
lnkContactToContract, lnkContractToDocument, lnkFunctionalCIToProviderContract, ServiceFamily,
Service, lnkDocumentToService, lnkContactToService, ServiceSubcategory, SLA, SLT, lnkSLAToSLT,
lnkCustomerContractToService, lnkProviderContractToService, lnkFunctionalCIToService,
DeliveryModel, lnkDeliveryModelToContact, CoverageWindowInterval, Holiday, HolidayCalendar,
CoverageWindow, URP_Profiles, URP_UserProfile, URP_UserOrg
as well as the Person filter codes:
finalclass, friendlyname, obsolescence_flag, name, status, org_id, org_id_friendlyname,
org_id_obsolescence_flag, org_name, email, phone, notify, function, first_name, employee_number,
mobile_phone, location_id, location_id_friendlyname, location_id_obsolescence_flag,
location_name, manager_id, manager_id_friendlyname, manager_id_obsolescence_flag,
manager_name, obsolescence_date, id
and the FunctionalCI filter codes:
finalclass, friendlyname, obsolescence_flag, obsolescence_date, name, description, org_id, org_id_friendlyname, org_id_obsolescence_flag, organization_name, business_criticity, move2production, id
And this is the Web-view of a Person:
I don't know if this information is helpful, but it's all I've got.
The downloaded information (csv) would then be processed with python and exported to pdf.
I'm new to Itop-OQL and everything I know about it is from this page: https://www.itophub.io/wiki/page?id=2_4_0%3Aoql%3Aexample. I'm sorry if I made some stupid mistakes or the solution to this problem is super simple!
Context
Functional CIs of a Person are represented as an "indirect linkedset" in iTop, which means that there is an intermediate class in between to store the relation and any data that it would contain (eg. the "role" in the Person / Team link).
The class corresponding to this specific link is named lnkContactToFunctionalCI, you can find it in the "Datamodel viewer" (here is what it looks like on the online demo, use admin/admin credentials) which is in the "Administration" menu. It displays all classes linked to a specific class.
Solution
You should try with an OQL query like SELECT lnkContactToFunctionalCI WHERE contact_id_friendlyname LIKE 'Ex Sample%'

Core WLAN MCS Index?

I'm trying to recreate the information displayed for the current Wi-Fi network when option-clicking on the Wi-Fi status bar item. One of the parameters shown is the MCS Index, but I can't find any way to query this value using the CWInterface class, which is where I am getting most of the other data:
if let interface = CWWiFiClient.shared().interface() {
rssi = interface.rssiValue()
noise = interface.noiseMeasurement()
// etc.
}
Since both the Wi-Fi status bar item and the airport command line tool display the MCS Index, it seems like there should be some way to query it:
MacBook:~ mark$ /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -I
agrCtlRSSI: -46
agrExtRSSI: 0
agrCtlNoise: -90
agrExtNoise: 0
state: running
op mode: station
lastTxRate: 878
maxRate: 1300
lastAssocStatus: 0
802.11 auth: open
link auth: wpa2-psk
BSSID: xx:xx:xx:xx:xx:xx
SSID: MyWiFi
MCS: 7
channel: 149,80
I've also seem some Python sample code that seems to indicate that the MCS Index should be available, but I don't see it in the docs or code completion.
Is there some way to get this value through Core WLAN or some other framework, or is this something I need to calculate based on other values?
I found another Python script wifi_status.py
which reports the WiFi status. From the lines
def wifi_status(properties=('bssid', 'channel', 'txRate', 'mcsIndex', 'rssi', 'noise')):
xface = CWWiFiClient.sharedWiFiClient().interface()
while True:
yield({name: getattr(xface, name)() for name in properties})
one can conclude that these attributes can be retrieved with
Key-Value Coding.
And that really works:
if let iface = CWWiFiClient.shared().interface() {
if let mcsIndex = iface.value(forKey: "mcsIndex") as? Int {
print(mcsIndex)
}
}
But I have now idea if that approach is officially supported,
or will work in the future, so use at your own risk.

External signature on a smart card

I am using a smart card that is signing a SHA-1 hash of a document, and compute a 256 bytes digital signature.
I am using the code posted on this question - iText signing PDF using external signature with smart card.
My problem is that I get the error:" The document has been altered or corrupted since the signature was applied".
I am using a GUI to create the hash and then send the signed 256 bytes that is computed on the card to the signing functions .
Here is my code:
hash creating code of filepath pdf document:
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
SHA256 sha2 = SHA256.Create();
//sha2.ComputeHash
byte[] pdfBytes = System.IO.File.ReadAllBytes(filePath);
byte[] hash = null;
hash= sha1.ComputeHash(pdfBytes);
the above code is used in one of the GUI functions to create the hash of the document
namespace EIDSmartCardSign
{
class PdfSignature
{
private string outputPdfPath;
private string certPath;
byte[] messageDigest;
private string inputPdfPath;
public PdfSignature(byte[] messageDigest, string inputPdfPath,string outputPdfPath)
{
this.messageDigest = messageDigest;
this.outputPdfPath = outputPdfPath;
this.inputPdfPath = inputPdfPath;
}
public void setCertPath(string certPath)
{
this.certPath = certPath;
}
public void signPdf()
{
X509Certificate2 cert = new X509Certificate2();
cert.Import(certPath); // .cer file certificate obtained from smart card
X509CertificateParser certParse = new Org.BouncyCastle.X509.X509CertificateParser();
Org.BouncyCastle.X509.X509Certificate[] chain = new Org.BouncyCastle.X509.X509Certificate[1] ;
chain[0] = certParse.ReadCertificate(cert.RawData);
X509Certificate2[] certs;
PdfReader reader = new PdfReader(inputPdfPath);
FileStream fout = new FileStream(outputPdfPath,FileMode.Create);
PdfStamper stamper = PdfStamper.CreateSignature(reader, fout, '\0',null,true);
PdfSignatureAppearance appearance = stamper.SignatureAppearance;
appearance.SignatureCreator = "Me";
appearance.Reason = "Testing iText";
appearance.Location = "On my Laptop";
iTextSharp.text.Rectangle rec = new iTextSharp.text.Rectangle(50, 50, 250, 100);
appearance.SetVisibleSignature(rec, 1, "Signature");
IExternalSignature extSignature= new MyExternalSignature("SHA-1",this.messageDigest);
MakeSignature.SignDetached(appearance, extSignature, chain, null, null, null, 0, CryptoStandard.CMS);
//MakeSignature.
}
}
}
Your hash creating function
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
SHA256 sha2 = SHA256.Create();
//sha2.ComputeHash
byte[] pdfBytes = System.IO.File.ReadAllBytes(filePath);
byte[] hash = null;
hash = sha1.ComputeHash(pdfBytes);
calculates the wrong hash value.
Have a look at this answer on Information Security Stack Exchange, in particular the sketch
shows that to get the document bytes to sign you do not take the original PDF but instead have to prepare it for integrating the signature container (add signature field, field value with some space reserved for the signature container, and field visualization) and then hash all the bytes except the space reserved for the signature container.
Furthermore, even this naked hash is not the data to sign. Instead a set of attributes is built, one of them containing the document hash calculated as above, other ones containing references to the signer certificate etc., and these attributes are to be signed.
Thus, instead do what you already claimed to be doing:
I am using the code posted on this question - iText signing PDF using external signature with smart card.
In particular the code there does not sign the hash of the whole file but instead uses the data the method Sign of the IExternalSignature implementation receives as parameter which is constructed as explained above.
More details
In a comment the OP said
The card I am working with expects a 20 bytes hash.
20 bytes would be typical for a naked hash generated by either SHA1 or RIPEMD-160. According to your question text, I assume the former algorithm is used. (This by the way indicates that the context does not require a high security level as SHA1 effectively is already phased out or in the process of being phased out for such use cases.)
What steps are needed to further create this hash After hashing the contents of the pdf?
Simply do as in the IExternalSignature implementation in the question you referenced:
public virtual byte[] Sign(byte[] message) {
byte[] hash = null;
using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider())
{
hash = sha1.ComputeHash(message);
}
byte[] sig = MySC.GetSignature(hash);
return sig;
}
(Obviously chances are that your smart card signing routine is not called MySC.GetSignature and you have to replace that call accordingly...)
As your card appears to expect a naked hash value in contrast to the card of the OP of the referenced question, this should work for you.
Where can I find examples of creating the aformentioned integrated signature container?
In the examples to the iText white paper Digital Signatures for PDF Documents.
After the signature process, I have 256 bytes signed data, 3 .cer certificates exported from the card.
256 bytes signed data sounds like a naked signature generated using RSA or RSASSA-PSS with a 2048 bit key size.
That been said, you need the signer certificate before signing: In most relevant profiles the signed attributes have to contain a reference to the signer certificate. In the code in the question you referenced that signer certificate is handled here
public void StartTest(){
X509Certificate2 cert = new X509Certificate2();
cert.Import("cert.cer"); // certificate obtained from smart card
X509CertificateParser certParse = new Org.BouncyCastle.X509.X509CertificateParser();
Org.BouncyCastle.X509.X509Certificate[] chain = new Org.BouncyCastle.X509.X509Certificate[] { certParse.ReadCertificate(cert.RawData) };
[...]
MyMakeSignature.SignDetached(appearance, externalSignature, chain, null, null, tsc, 0, CryptoStandard.CADES);
In particular you have to identify the correct signer certificate among those three certificate your card returns; otherwise you might have the same issue as the OP in the referenced question.
How do I create the Contents object when I have all of this data?
Considering what you said about your use case, chances are good that you really merely have to use the code posted of the question iText signing PDF using external signature with smart card with minor adaptions.

What is the proper way to use a findBy’Field’ method?

I am trying to compare an email address inputed from a form to what is already in the database and I figure the best way to do so is with using a findByEmail method.
I expected that to find the email address for a specific entry in the table but instead it returns the whole entry (first name, last name, and more…).
How do I only find the email address of the entry in the table?
I know I can use a foreach to iterate through the entry but I think that kinda defeats the purpose of using a findByEmail function.
Here’s what I’ve tried so far:
$formEmail = $form->get('email')->getData();
$personEmail = $em->getRepository('UserBundle:User')->findByEmail($formEmail); //Should just find the email address of a person in the database.
var_dump($personsEmail); //returns the whole row associated with the email address (first name, last name…..)
var_dump(if($formEmail == $personEmail));die; //returns false when it should be true because it finds the whole row instead of the email address
If you fetched the entity successfully by email then the email must match.
$formEmail = $form->get('email')->getData();
$person = $em->getRepository('UserBundle:User')->findOneByEmail($formEmail);
if ($person instanceof User) {
// you found a user by email, so the email therefore must match ...
}
Note, use findOneBy not findBy, then you will fetch the object directly instead of in a collection.
Alternatively if you must fetch just the email address for comparison.
$email = $em->createQueryBuilder()
->select('u.email')
->from('UserBundle:User', 'u')
->where('u.email = :email')
->setParameter('email', $formEmail)
->getQuery()
->getSingleScalarResult()
;
Note though that you could just use $person->getEmail() in my first example for the same result.

How to use consistent hashing in memcached c client?

I am using libmemcached c client for set and get the memcache value.
memcached_server_st *servers = NULL;
memcached_st *memc;
memcached_return rc;
char *key= "keystring";
char *value= "keyvalue";
// memcached_server_st *memcached_servers_parse (char *server_strings);
memc= memcached_create(NULL);
servers= memcached_server_list_append(servers, "localhost", 5555, &rc);
servers= memcached_server_list_append(servers, "localhost", 5566, &rc);
rc= memcached_server_push(memc, servers);
if (rc == MEMCACHED_SUCCESS)
fprintf(stderr,"Added server successfully\n");
else
fprintf(stderr,"Couldn't add server: %s\n",memcached_strerror(memc, rc));
rc= memcached_set(memc, key, strlen(key), value, strlen(value), (time_t)0, (uint32_t)0);
if (rc == MEMCACHED_SUCCESS)
fprintf(stderr,"Key stored successfully\n");
else
fprintf(stderr,"Couldn't store key: %s\n",memcached_strerror(memc, rc));
return 0;
I want to use the consistent hashing algorithm for set and get the key.
http://docs.libmemcached.org/memcached_behavior.html#memcached_behavior_setlink
But i don't know how to implement this.code snippets or reference links are very much appreciated.
Thanks in advance.
Go to the link http://docs.libmemcached.org/memcached_behavior.html#memcached_behavior_setlink
You can see two method to make it.
first one
MEMCACHED_BEHAVIOR_DISTRIBUTION
Using this you can enable different means of distributing values to servers.
The default method is MEMCACHED_DISTRIBUTION_MODULA. You can enable consistent hashing by setting MEMCACHED_DISTRIBUTION_CONSISTENT. Consistent hashing delivers better distribution and allows servers to be added to the cluster with minimal cache losses. Currently MEMCACHED_DISTRIBUTION_CONSISTENT is an alias for the value MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA.
second one
MEMCACHED_BEHAVIOR_KETAMA
Sets the default distribution to MEMCACHED_DISTRIBUTION_CONSISTENT_KETAMA and the hash to MEMCACHED_HASH_MD5.
example
memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_KETAMA, 1);